解决 org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does no
生活随笔
收集整理的這篇文章主要介紹了
解决 org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does no
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1.getCurrentSession()是必須提交事務(wù)的。故使用getSessionFactory().getCurrentSession()時,這個方法一定是要配置聲明式事務(wù)管理。
2.openSession()恰恰是與以上的方法想法,它不需要提交事務(wù)。但是他的資源必須手動關(guān)閉。
相對以上兩點(diǎn),解決方法有
1.獲得session時使用openSession()。
2.若用到getCurrenctSession(),需在sessionFactory中配置(當(dāng)然也可以使用注解,在 service類加上事務(wù)@Transactional)
總結(jié)
以上是生活随笔為你收集整理的解决 org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does no的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: redis之mq实现发布订阅模式
- 下一篇: 什么是分布式事务以及有哪些解决方案?