Can not execute delete operation by using deleteBy custom method in spring data repository

问题: When I try to delete data from my service class using deleteBy() custom method in spring data repository it gives following error. javax.persistence.TransactionRequiredEx...

问题:

When I try to delete data from my service class using deleteBy() custom method in spring data repository it gives following error.

javax.persistence.TransactionRequiredException: No EntityManager with actual transaction available for current thread - cannot reliably process 'remove' call

I tried with making method and service class @Transactional. Then autowire members get null. Those were initialize without @Transactional.


回答1:

Load all the data that need to be deleted. getBYId(id); And use that collection to execute deleteAll() operation. That solve the issue.


回答2:

You have to load the object first

  • 发表于 2019-03-31 10:11
  • 阅读 ( 283 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除