Spring JPA 报Not supported for DML operations 错误

在运行JPA修改数据代码报 Not supported for DML operations 错误

@Query(value = "update User user set user.address = :address where user.id = :id ")
    void findByUpdateUser(@Param("id") int id,@Param("address") String address);

解决办法就是在上面加上@Modifying 修改注解

 @Modifying
    @Query(value = "update User user set user.address = :address where user.id = :id ")
    void findByUpdateUser(@Param("id") int id,@Param("address") String address);

运行上面代码你会发现又会报“Executing an update/delete query”的错,这时你只需要你的在业务类Service类上面@Service注解那添加事务注解@Transactional就OK了(或者在update和delete方法@xxxMapping上面注解@Transactional)

posted @ 2018-12-05 18:28  静静别跑  阅读(525)  评论(0编辑  收藏  举报