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