Why this No Session found for current thread exceptions in spring 3.1 and hibernate 4

前端 未结 3 1745
名媛妹妹
名媛妹妹 2021-01-03 13:32

I was trying to configure spring 3.1 and hibernate. I have written a simple test project. where I have user domain and userDao and its implementation

let me show yo

3条回答
  •  借酒劲吻你
    2021-01-03 13:42

    There are no transactions in your sample project. Add:

    
    

    And annotate your DAO with @Transactional:

    @Transactional
    @Repository 
    public class UserDaoImpl implements UserDao
    

    Two notes:

    • you are correctly marking your DAO with @Repository, but it only handles exception translation:

      A class thus annotated is eligible for Spring DataAccessException translation

    • consider placing @Transactional on higher level classes (@Services), see What is the right way to use spring MVC with Hibernate in DAO, sevice layer architecture for discussion

提交回复
热议问题