hibernate openSession()和getCurrentSession()区别

    <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  



你可能感兴趣的:(hibernate openSession()和getCurrentSession()区别)