Hibernate openSession与getCurrentSession的区别:
1.使用getCurrentSession时要在配置文件中配置属性:
<property name="hibernate.current_session_context_class">thread</property>(使用JDBC事务)
或
<property name="hibernate.current_session_context_class">jta</property>(使用JTA事务)
2.getCurrentSession创建时会自动绑定到当前线程中,openSession不会.
3.openSession要显示地调用close()方法,而getCurrentSession使用后不用关闭,它会在事务提交(commit)或回滚(rollback)时自动关闭.
可以使用getCurrentSession来实现编程式事务
openSession与getCurrentSession的区别
最新推荐文章于 2025-07-28 23:27:29 发布