openSession,每次重新創建連接對象,需要手動關閉,否則可能導致連接池溢出。
采用getCurrentSession()創建的Session會綁定到當前的線程中去、而采用OpenSession()則不會。
采用getCurrentSession()創建的Session在commit或rollback后會自動關閉,采用OpenSession()必須手動關閉。
采用getCurrentSession()需要在Hibernate.cfg.xml配置文件中加入配置current_session_context_class
采用getCurrentSession()創建的Session會綁定到當前的線程中去、而采用OpenSession()則不會。
采用getCurrentSession()創建的Session在commit或rollback后會自動關閉,采用OpenSession()必須手動關閉。
采用getCurrentSession()需要在Hibernate.cfg.xml配置文件中加入配置current_session_context_class
2018-04-25
//4.35之后
//創建會話工廠對象
sessionFactory = new Configuration().configure().buildSessionFactory();
//Hibernate5.x版本創建會話對象
session = sessionFactory.openSession();
//開啟事務
transaction = session.beginTransaction();
//創建會話工廠對象
sessionFactory = new Configuration().configure().buildSessionFactory();
//Hibernate5.x版本創建會話對象
session = sessionFactory.openSession();
//開啟事務
transaction = session.beginTransaction();
2018-04-12
INFO: HHH000230: Schema export complete
報錯解決:可能是地址寫錯了,如 把“d:”寫成了"d",少了個冒號而已。加上就可以了。
報錯解決:可能是地址寫錯了,如 把“d:”寫成了"d",少了個冒號而已。加上就可以了。
2018-04-12
找bug找了1小時 看得我眼都花了,最后的問題是mapping映射那里不能像老師那么直接寫?。?!要寫上完整包名 <mapping resource="hibernate_001/Students.hbm.xml"/> ?。。?!
2018-04-11
Junit5的注解要使用BeforeEach 和AfterEach
Before和After并沒有用啊
Before和After并沒有用啊
2018-04-11
hibernate的使用過程
Configuration cfg = new Configuration().configure();
SessionFactory factory = cfg.buildSessionFactory();
Session session = factory.openSession();
Transaction tx=session.beginTransaction();session.save(stu);tx.commit();session.close();factory.close();
Configuration cfg = new Configuration().configure();
SessionFactory factory = cfg.buildSessionFactory();
Session session = factory.openSession();
Transaction tx=session.beginTransaction();session.save(stu);tx.commit();session.close();factory.close();
2018-04-11
第二遍了,建議大家別用老師提供的jar包,自己去下載最新的jar包,因為新版本和老師的有些用法不一樣,自己對照官方文檔多練習也是好的
2018-04-04
用最新的hibernate時,自動建表失敗,方言MySQLDialect應該改為MySQL5Dialect
2018-04-04
創建一個hiberbate步驟
1,創建hibernate的配置文件
2,創建持久化類
3,創建對象-關系映射文件
4,通過hibernate api編寫訪問數據庫的代碼
1,創建hibernate的配置文件
2,創建持久化類
3,創建對象-關系映射文件
4,通過hibernate api編寫訪問數據庫的代碼
2018-03-26