Spring and hibernate: No Session found for current thread

后端 未结 6 1494
生来不讨喜
生来不讨喜 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:53

    I solved the same problem with following 2 steps

    1. Placed @Transactional on the service method as suggested jordan002 in his answer on this page.

    2. One more thing,If you have 2 configuration files: say application-context.xml(For DB and Application Context Specific configuration) and webmvc-context.xml(For web/controller specific configuration), then you should scan the packages different for your controllers and dao.

      The webmvc-context.xml is loaded after application-context.xml. I think the DAO class is loaded first with transactional references when the application-context.xml is loaded, but it is replace with another object, without transactional references, when webmvc-context.xml is loaded.

      Any way, I resolve the problem with specific packages scanned:

      
      

      for application-context.xml

      and

      
      

      for webmvc-context.xml.

提交回复
热议问题