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