Could not obtain transaction-synchronized Session for current thread

在用spring 4.1.2 + hibernate 4.2.0開發時,調用getSessionFactory().getCurrentSession()方法報異常:

org.hibernate.HibernateException: Could not obtain transaction-synchronized Session for current thread


異常原因:


解決辦法:

在Service層加上一個 @Transactional 的註解,聲明這個service所有方法需要事務管理,每一個業務方法開始時都會打開一個事務。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章