I create custom method in Spring repository
@Transactional
@Modifying(clearAutomatically = true)
@Query("UPDATE Order co SET co.orderStatus =:status WHERE co.orderStatus =:newStatus")
int updateOrderStatus(@Param("status") OrderStatus status, @Param("newStatus") OrderStatus newStatus);
and call it in service:
log.info("started");
int i = orderRepository.updateOrderStatus(OrderStatus.CREATED, OrderStatus.PENDING);
log.info("updates: " + i);
And I see in logs:
INF 15:43:45.102 started
INF 15:43:46.035 updates: 0
In DB I have 3 rows with CREATED
status. I have not err and rows not update.
@Column(name = "order_status")
@Enumerated(EnumType.STRING)
private OrderStatus orderStatus;
findAllByOrderStatus(OrderStatus.CREATED) get 3 rows
Your query is the other way around: