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 发布
本文详细对比了 Hibernate 中 openSession 和 getCurrentSession 的主要区别,包括配置要求、线程绑定及关闭方式等,并介绍了如何利用 getCurrentSession 实现编程式事务。
348

被折叠的 条评论
为什么被折叠?



