Spring and hibernate: No Session found for current thread

后端 未结 6 1481
生来不讨喜
生来不讨喜 2020-11-28 11:05

im gettting the following error

org.hibernate.HibernateException: No Session found for current thread
at org.springframework.orm.hibernate4.SpringSessionCont         


        
6条回答
  •  渐次进展
    2020-11-28 11:58

    I'll just add something that took me some time to debug : don't forget that a @Transactional annotation will only work on "public" methods.

    I put some @Transactional on "protected" ones and got this error.

    Hope it helps :)

    http://docs.spring.io/spring/docs/3.1.0.M2/spring-framework-reference/html/transaction.html

    Method visibility and @Transactional

    When using proxies, you should apply the @Transactional annotation only to methods with public visibility. If you do annotate protected, private or package-visible methods with the @Transactional annotation, no error is raised, but the annotated method does not exhibit the configured transactional settings. Consider the use of AspectJ (see below) if you need to annotate non-public methods.

提交回复
热议问题