区别:
getCurrentSession()创建的Session会绑定到当前的线程中去、而采用OpenSession()则不会。
getCurrentSession()创建的Session在commit或rollback后会自动关闭,采用OpenSession()必须手动关闭。
使用getCurrentSession()需再核心配置文件中添加:
<property name="hibernate.current_session_context_class">thread</property>
由此,上一篇中的工具类中添加geCurrentSession()方法