Optimistic locking in a stateless application with JPA / Hibernate
The server loads the item with the EntityManager which returns Item(id = 1, version = 1, name = “a”), it changes the name and persist Item(id = 1, version = 1, name = “b”). Hibernate increments the version to 2. That’s a misuse of the JPA API, and the root cause of your bug. If … Read more