问题:在调用JPA进行更新操作时报错如下:

Executing an update/delete query; nested exception is javax.persistence.TransactionRequiredException:

代码:

Executing an update/delete query; nested exception is javax.persistence.TransactionRequiredException

原因:其实提示已经很明确了,没有使用事物

解决方案:方法上增加@Transactional

 

@Transactional

@Modifying(clearAutomatically = true)

@Query("update ToOrderVO toOrderVO set toOrderVO.orderStatusId = ?3 where toOrderVO.orderCode = ?1 and toOrderVO.orderStatusId=?2")

public int updateByOrderCodeAndOrderStatusId(@Param(value = "order_code") String helperCode,@Param(value = "order_status_id") int orderStatusIdFrom ,@Param(value = "order_status_id") int orderStatusIdTo);

 

备注:

1.更新info表下指定id的status字段, 这里使用了原生的sql语句。

[email protected] 注解用于提交事务,若没有带上这句,会报事务异常提示。

[email protected](clearAutomatically = true) 自动清除实体里保存的数据。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-05-30
  • 2021-12-26
  • 2021-08-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-04
  • 2021-10-24
  • 2022-12-23
  • 2022-12-23
  • 2021-04-27
相关资源
相似解决方案