The best way to use OPTIMISTIC_FORCE_INCREMENT with JPA and Hibernate

Introduction In this article we are going to see what is the best way to use the OPTIMISTIC_FORCE_INCREMENT LockModeType with JPA and Hibernate. With LockModeType.OPTIMISTIC, the locked entity version is checked towards the end of the current running transaction, to make sure we don’t use a stale entity state. Because of the application-level validation nature, this strategy is susceptible to race-conditions, therefore requiring an additional pessimistic lock . The LockModeType.OPTIMISTIC_FORCE_INCREMENT not only it checks the expected locked entity version, but it also increments it. Both the check and the update happen in… Read More