getCurrentSession和openSession的区别?
A:采用getCurrentSession创建的session会绑定到当前的线程中,采用openSesion创建的session则不会绑定到当前的session中。
B:用getCurrentSession创建的session在commit和rollback的时候会自动的关闭,而采用openSesion创建的session则需要手动进行关闭。
C:使用getCurrentSession()需要在hibernate.cfg.xml文件中加入如下配置:
* 如果使用的是本地事务(jdbc事务)既是与一个数据库联系
<property name="hibernate.current_session_context_class">thread</property>
* 如果使用的是全局事务(jta事务)既是与多个数据库向联系
<property name="hibernate.current_session_context_class">jta</property>