Spring JPA报错:Not supported for DML operations

时间:2023-05-12 17:45:03

在一个Spring JPA项目中,执行更新或删除是报错:

Not supported for DML operations

解决方法:只需要添加注解@Modifying即可。

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