hibernate的配置方式有兩種
第一種為:編寫hibernate.cfg.xml,並且為每個對映類編寫.hbm.xml檔案
,hibernate.cfg.xml檔案的內容如下:
jdbc for mysql
jdbc:mysql://localhost:3306/demo
root
admin
com.mysql.jdbc.driver
org.hibernate.dialect.mysqldialect
其中,hibernate.cfg.xml檔案位置的指定由hibernatesessionfactory類來指定,其中這個類的**如下:
package com.hibernate.util;import org.hibernate.hibernateexception;
import org.hibernate.session;
import org.hibernate.sessionfactory;
import org.hibernate.cfg.configuration;
@suppresswarnings("unchecked")
public class hibernatesessionfactory catch(exception e)
}session = sessionfactory.opensession();
threadlocal.set(session);
}return session;
}public static void closesession()throws hibernateexception}}
org.gjt.mm.mysql.driver
jdbc:mysql://localhost:3306/demo
root
admin
org.hibernate.dialect.mysqldialect
true
如果有新的類對映檔案要加入進來,只需要在標籤中加上乙個標籤,並且在中間填入類對映檔案的具體位置,像user.hbm.xml檔案一樣
SSH整合 Hibernate延遲載入引發的問題
bug描述 如圖,所屬部門沒有顯示,所屬部門是乙個實體類,員工也是乙個實體類,其中乙個屬性就是部門。這裡之所以沒有顯示就是因為hibernate延遲載入引發的。延遲載入介紹 這裡就是因為一開始載入employee集合的時候,因為department屬性未被使用,所以採用了延遲載入。當在jsp頁面遍歷...
spring整合hibernate中遇到的坑
這個錯誤是hibernate版本在3.5以上的時候還整合了hibernate annotations包,報出的錯誤。解決方法 檢查hibernate版本,如果在3.5以上去掉hibernate annotations包 2.org hibernate hibernateexception unsup...
ssh整合中的問題
path regist scope request type com.yidu.action.registaction property contextconfiglocation 當ssh整合之後 占用的中心控制器擴充功能,controller?只能有乙個中心控制器不能實現requestproce...