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

前端 未结 9 729
情歌与酒
情歌与酒 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 18:09

    I resolved this by adding @Transactional to the base/generic Hibernate DAO implementation class (the parent class which implements the saveOrUpdate() method inherited by the DAO I use in the main program), i.e. the @Transactional needs to be specified on the actual class which implements the method. My assumption was instead that if I declared @Transactional on the child class then it included all of the methods that were inherited by the child class. However it seems that the @Transactional annotation only applies to methods implemented within a class and not to methods inherited by a class.

提交回复
热议问题