<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
</session-factory>
</hibernate-configuration>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
</session-factory>
</hibernate-configuration>
2017-03-20
在網上找了一下資料,有篇博客是這樣寫,getCurrentSession是從當前上下文中獲取Session并且會綁定到當前線程,第一次調用時會創建一個Session實例,如果該Session未關閉(注意這句),后續多次獲取的是同一Session實例;事務提交或者回滾時會自動關閉Sesison,無需人工關閉 博客鏈接如下http://itlab.idcquan.com/Java/Hibernate/961463.html 我在MyEclipse上照著老師的代碼敲了,發現即使是getCurrentSession方法返回的連接對象的hashCode仍然不同,不知道是不是老師講錯了,各位大神請發表見解
2017-03-20
在destroy方法里運行的時候會出現空指針異常,所以要加個非空判斷,如下
@After
public void destroy()
{
transaction.commit();
session.close();
if(sessionFactory!=null){
sessionFactory.close();
}
}
@After
public void destroy()
{
transaction.commit();
session.close();
if(sessionFactory!=null){
sessionFactory.close();
}
}
2017-03-18
V4版本的hibernate可能出現 org.hibernate.MappingNotFoundException錯誤
http://www.cnblogs.com/wangxiaoha/p/6231888.html
http://www.cnblogs.com/wangxiaoha/p/6231888.html
2017-03-18
MappingNotFoundException: *.hbm.xml Not Found.,說明這個文件的位置是不對的.老師的課程中在hibernate.cfg.xml文件中直接寫 <mapping resource="*.hbm.xml" />, 那是因為hbm.xmol文件就放在src目錄下。如果你的*.hbm.xml文件是放在com.imooc.entity目錄下,也就是和Student類處于同一目錄,你的hibernate.cfg.xml文件中就得這么寫 <mapping resource="com/imooc/entity/*.hbm.xml" />,這樣寫就可以找到并正確加載了!
2017-03-15