JPA无法删除对象【实际项目解决办法】


并非通用, 根据自己实际情况来

 

不能删除前的dao方法

public void delete(CmsProjectNew bean);

 

可以删除后的dao方法

@Modifying
@Query("delete CmsProjectNew bean where bean.id in (?1)")
public void deleteById(Integer id);

 

 

【下面错误原因】——service方法增加@Transactional

@Transactional
public void delete(int id) {
dao.deleteById(id);
}

严重: Servlet.service() for servlet [background] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Executing an update/delete query; nested exception is javax.persistence.TransactionRequiredException: Executing an update/delete query] with root cause
javax.persistence.TransactionRequiredException: Executing an update/delete query

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM