您的足迹:首页 > 未分类 >关于jpa一些报错No operations allowed after statement closed和 not supported for dml operations

关于jpa一些报错No operations allowed after statement closed和 not supported for dml operations

今天开发项目的时候发觉报了一个No operations allowed after statement closed

 

List<WebsiteProCategoryShield> shieldList= websiteProCategoryShieldDao.findByWebsiteId(websiteId);
  for(WebsiteProCategoryShield w:shieldList){
        websiteProCategoryShieldDao.delete(w.getWebsiteProCategoryShieldId());
  }

上诉代码是先从数据库查出,然后删除,我不知道错误在哪里?于是我把代码改为

业务层

websiteProCategoryShieldDao.deleteByWebsiteId(websiteId);

 

持久层

@Query("delete from WebsiteProCategoryShield w where w.websiteId=?1")
 public void deleteByWebsiteId(Long websiteId);

 

 

却报了not supported for dml operations的错误

 

仔细研究发觉原来是忘记了在持久层语句中加上@modifying 加上后可以解决问题

@Modifying
 @Query("delete from WebsiteProCategoryShield w where w.websiteId=?1")
 public void deleteByWebsiteId(Long websiteId);

 

相关推荐

网友评论(0)