Sanjay Sharma
Sanjay Sharma

Reputation: 21

Spring with JPA Hibernate 5.0.3 executing same update queries twice, First with updated values and then with old values

I am using Spring (not boot) 4.1.1 with JPA2 and hibernate version 5.0.3-final. What we observed is, In a certain flow where our JMS listener is getting a message from AWS SQS, 99% of the transactions execute 3 update queries to update the database but, in 1% cases, after these 3 queries, it executes same 3 queries again with older values, resulting in a flip flop of values. Sometimes these 3 sets of queries are few seconds apart and sometimes a few minutes. We initially thought that maybe another call to this method is causing it but there is only one set of logs available in our log files all the time. I am suspecting this to be related with threads holding session state but not sure as I haven't seen such thing with hibernate before. According to recent observation this only happens with update queries.

Upvotes: 0

Views: 466

Answers (1)

Sanjay Sharma
Sanjay Sharma

Reputation: 21

It was being caused by another flow that was calling merge() over the same entity and causing reload of itself and some of its children.

Upvotes: 1

Related Questions