OpenSession与getCurrentSession的区别
生活随笔
收集整理的這篇文章主要介紹了
OpenSession与getCurrentSession的区别
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
getCurrentSession 使用當前的Session
OpenSession ?創建一個行的Session
1.getCurrentSession創建的Session會更當前線程綁定,而OpenSession不會。
2.getCurrentSession創建的線程會在事物提交或回滾的時候自動關閉,而OpenSession必須得手動關閉。
在Hibernagte中使用getCurrentSession中有這兩種配法:
1.(本地事物)對單個數據庫進行操作,也就是只針對一個事物(jdbc事物)
? <property name="current_session_context_class">thread</property>
如果沒有會報異常:
?
2.(全局事務)多個數據庫之間進行操作,并且只能在一個事物中操作(jta事務)
<property name="current_session_context_class">jta</property>
?
轉載于:https://www.cnblogs.com/szj-ang/p/6629143.html
總結
以上是生活随笔為你收集整理的OpenSession与getCurrentSession的区别的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PhpStrom xdeubg jet
- 下一篇: Android之微信支付