Reputation: 179
I am updating using @Modifying and just after update I am fetching data using the repository. But the data fetched is not the updated data but the data before update is done. When I fetch the same using other GET api then the updated data is fetched but not just after updating in the same method.
My Service class update method:
public Response update(Integer value, Long id) {
repository.updateValue(value, id);
Response res = repository.findById(id);
return res;
}
My Repository class update method:
@Transactional
@Modifying
@Query(value = "update T1 set value = :value where id = :id",
nativeQuery = true)
int updateValue(Integer value, Long id);
As mentioned I am getting the previous values in "res". Can anyone help with this issue?
Upvotes: 5
Views: 1752
Reputation: 179
After adding clearAutomatically=true in @Modifying annotation the update worked just fine.
@Transactional
@Modifying(clearAutomatically = true)
@Query(value = "update T1 set value = :value where id = :id",
nativeQuery = true)
int updateValue(Integer value, Long id);
Upvotes: 5