openSession与getCurrentSession的区别

来源:互联网 发布:魔幻视频特效软件 编辑:程序博客网 时间:2024/06/10 07:22

 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来实现编程式事务

原创粉丝点击