No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here

前端 未结 9 727
情歌与酒
情歌与酒 2020-12-23 17:03

I am getting this exception when I call a DAO method which uses SessionFactory.getCurrentSession(). The DAO class is annotated with @Transactional

9条回答
  •  攒了一身酷
    2020-12-23 17:50

    after I add the property:

    thread I get the exception like:

    org.hibernate.HibernateException: createQuery is not valid without active transaction
    org.hibernate.HibernateException: save is not valid without active transaction.
    

    so I think setting that property is not a good solution.

    finally I solve "No Hibernate Session bound to thread" problem :

    1.
    2.add to servlet-context.xml or dispatcher-servlet.xml
    3.add @Transactional after @Service and @Repository

提交回复
热议问题