Spring and hibernate: No Session found for current thread

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

    You annotated your Dao class with @Transactional, but not your service class. The line:

    Visitor storedVisitor =
        (Visitor) sessionFactory.getCurrentSession().get(Visitor.class,
                visitorDetails.getTfscNumber(), LockMode.NONE);
    

    requires you to be in a transaction.

    You can fix this by adding the @Transactional annotation to your ProfileService class, or just the registerVisitor() method.

提交回复
热议问题