openSession 和currentSession的区别
1.currentSession会和当前的事务绑定,openSession则不会
2.currentSession在事务回滚或事物提交之后会自动关闭session,openSession则 需要手动的关闭。
使用getCurrentSession需要配置:
如果是使用本地事务(jdbc事务)
<property name=”hibernate.current_session_context_class”>thread</property>
如果是使用全局事务(jta事务)
<property name=”hibernate.current_session_context_class”>jta</property>
getCurrentSession:当前Session对象
openSession:打开一个新的Session对象