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

后端 未结 4 1160
被撕碎了的回忆
被撕碎了的回忆 2021-01-04 21:16

I am getting error:

Exception in thread \"main\" org.hibernate.HibernateException: 
Could not obtain transaction-synchronized Session for current thread
         


        
4条回答
  •  时光取名叫无心
    2021-01-04 22:07

    You must enable the transaction support ( or @EnableTransactionManagement ) and declare the transactionManager and it should work through the SessionFactory.

    You must add @Transactional into your @Repository

    With @Transactional in your @Repository Spring is able to apply transactional support into your repository.

    Your Student class has no the @javax.persistence.* annotations how @Entity, I am assuming the Mapping Configuration for that class has been defined through XML.

    Ref

提交回复
热议问题