Improve solution for OR-Mapper_JPA_ff: Exercise 5
Context
Summary
The current solution is not matching the exercises goals and is not a good one too.
Using em.lock(from, LockModeType.PESSIMISTIC_WRITE);
does not guarantee that we can not get lost updates.
Even worse, we encounter locked transactions when using a different sequence of commands.
Steps to reproduce
(How one can reproduce the issue - this is very important)
What is the current issue behavior?
(What actually happens)
What is the expected correct behavior?
(What you should see instead)
Relevant logs and/or screenshots
(Paste any relevant logs - please use code blocks (```) to format console output, logs, and code as it's very hard to read otherwise.)
Possible fixes
Use @Version
for the accounting entity and try using a Timestamp as value.
Maybe we can create/update the table within code using a dynamic query.
Links
- Lost updates and locking: https://vladmihalcea.com/2014/09/14/a-beginners-guide-to-database-locking-and-the-lost-update-phenomena/
- JPA and locking: http://www.developer.com/java/manage-concurrent-access-to-jpa-entity-with-locking.html
- JPA entity versioning
@Version
: http://www.byteslounge.com/tutorials/jpa-entity-versioning-version-and-optimistic-locking - Explicit locking: https://www.dynatrace.com/blog/week-38-transactions-in-a-jpa-world/