I have a spring boot app, a REST service is called inside this rest call two separate DB operations are done (Spring Data JPA is being used). First one updates some database tables and second one reads from the said tables and do some operations.
@GetMapping("/process")
public void process(){
service1.updateValues();//updates the values
service2.readValuesAndProcess();//reads those updated values and execute some logic and persist at the end
}
Now the problem is;
Second method doesn't seem to read the updated values that are updated in the first method and somehow reads the values before the update. Both these methods are @Transactional
, Entities are @versioned
and when a save operation is called ObjectOptimisticLockingFailureException
is thrown.
In application.properties spring.jpa.open-in-view
property is true, when i change it to false everything works as expected but i can't guarantee that i won't get a lazyInitializationException
somewhere else.
I tried changing transactional methods propagation to REQUIRES_NEW and nothing changes.