在运行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)

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-16
  • 2022-02-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-04
  • 2021-12-31
  • 2022-03-09
  • 2021-11-01
  • 2022-12-23
  • 2022-01-12
  • 2021-08-30
相关资源
相似解决方案