Could not obtain transaction-synchronized Session for current thread

点点圈 提交于 2019-12-01 17:27:50

Just found it ... @EnableTransactionManagement was missing on my root configuration class.

Thanks everybody for the guidance.

I presume it is a problem of transactional proxy not being used (just a guess from the stacktrace). By default, spring uses a Jdk proxy for it, but that needs the service to be imported as an interface in the controller.

If it is the case, create an interface IPersonService containing relevant method from PersonService and import it in PersonController as @Autowired IPersonService personService; or even better, rename PersonService to PersonServiceImpl and make PersonService an interface.

And ... consistently do that for all your transactional services ...

Such scenario:

Use this Thumb Rule :

1) For Every @Entity @Table(name = "Table1")

Create corresponding Services, and Corresponding DAO.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!