Spring data jpa 自定义SQL语句遇到错误Not supported for DML operations

来源:互联网 发布:产品在淘宝没有展现 编辑:程序博客网 时间:2024/06/07 23:08
今天在自定义一个Update语句时运行遇到一个错误,显示Not supported for DML operations 也就是说不支持DML操作。我的UserRepository是继承的PagingAndSortingRepository接口,在看了JPA的文档之后,发现此接口不支持update事务,所以需要在注解上添加@Modifying。
以下是我的源码:
@Modifying
@Query("update User u set u.u_name=?2,u.u_sex=?3,u.u_date = ?4,u.u_minzu = ?5,u.u_area=?6,u.u_country=?7 where u.u_id =?1")
public void updateUserById(String u_id,String u_name,String u_sex,
                               String u_date, String u_minzu,String u_area,
                               String u_country);
0 0