I have problem with flush() method in entityManager. In my application I'm modifying object and after that I call em.flush() but I dont commit() changes, in the same time second user is modifying the same object and at the end he also calls em.flush() I expect that he will get OptimisticLockException at this moment, but no. I get exception only when i commit changes made by first user. Can someone explain it to me? Object's are versioned, Entity manager is session scope.
Asked
Active
Viewed 481 times
0
-
Transactions run in isolation. That's the I in [ACID](http://en.wikipedia.org/wiki/ACID). – JB Nizet May 17 '14 at 21:47
-
Ok but wird thing is that when second user is flushing, application for him freez(you are not able to do any thing, just hangs, suspend) until first user commit his changes, and then second user gets OptimisticLockExcpetion – bojek May 17 '14 at 23:16
-
1Freezing is exactly what it's supposed to do. The insert/update in the second transaction can't complete until the first is committed, because both are trying to touch the same row. – wrschneider May 18 '14 at 00:56
-
So is there any way to check in JPA if entity isDirty before calling flush. I would like to inform second user that this entity is being modified by another user? – bojek May 18 '14 at 11:07