1

I'm trying to increase performance by executing one request instead of updating each entity. The sql looks right and the call to this method is executed but I see no "update" executed in hibernate log.

@Modifying
@Query("UPDATE Order x SET x.reservedByClient = :value WHERE x.tourId = :id")
public void updateReservationStatus(@Param("value") Boolean value, @Param("id") Long id);

Any hints where to look ?

1
  • Arnie Schwarzvogel. just as the solution offered by Dvorog. the anotation "@Transactional" should be added. and you can try to solve the problem by yourself depend on the exeception log, in this case, i bet that you have received the log such as Executing an update/delete query; nested exception is javax.persistence.TransactionRequiredException: Executing an update/delete query", Commented Jul 18, 2018 at 7:45

1 Answer 1

2

Modifiying queries should be wrapped in a transaction. Try adding @Transactional to the query.

@Modifying
@Query("UPDATE Order x SET x.reservedByClient = :value WHERE x.tourId = :id")
@Transactional
public void updateReservationStatus(@Param("value") Boolean value, @Param("id") Long id);
Sign up to request clarification or add additional context in comments.

2 Comments

@Transactional will be used in the service layer. can we use in the repository level . correct me if i am wrong.
@Transactional can be used in both layers (service and repository). It depends on what you want to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.