hibernate openSession()和getCurrentSession()区别

≡放荡痞女 提交于 2019-12-02 10:09:04
    <1> getCurrentSession创建的session会和绑定到当前线程,而openSession(重新建立一个新的session )不会。
    <2> getCurrentSession创建的线程会在事务回滚或事物提交后自动关闭,而openSession必须手动关闭
    <3> getCurrentSession设置本地事务时要,在hibernate.cfg.xml文件里进行如下设置:
<property name=“hibernate.current_session_context_class”>thread</property>

    参考 :http://blog.csdn.net/loveyout/article/details/4193894  



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!