hibernat中openSession()与getCurrentSession()

区别:

getCurrentSession()创建的Session会绑定到当前的线程中去、而采用OpenSession()则不会。

getCurrentSession()创建的Session在commit或rollback后会自动关闭,采用OpenSession()必须手动关闭。

使用getCurrentSession()需再核心配置文件中添加:

<property name="hibernate.current_session_context_class">thread</property>

由此,上一篇中的工具类中添加geCurrentSession()方法

猜你喜欢

转载自blog.csdn.net/qq_40605913/article/details/81461142
今日推荐