且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

春天如何管理hibernate会话生命周期

更新时间:2022-10-18 08:18:01

The SessionFactory is created by Spring using given dataSource and is taking its DB connections from connection pool. We get a Hibernate session via SessionFactory.getCurrentSession(). then start transaction, do the work and then commit() or rollback(), and at the end close the connection(connection object will be returned to the pool). Hibernate session factory will be destroyed/closed when we either stop application or shutdown the server. And By default, Thread implementations of CurrentSessionContext will be used, if you use HibernateTransactionManager. If you want to use, jta implementation: you have to use "JtaTransactionManager" as a Transaction manager.