How does LockModeType.OPTIMISTIC work in JPA and Hibernate

Explicit optimistic locking In my previous post, I introduced the basic concepts of Java Persistence locking. The implicit locking mechanism prevents lost updates and it’s suitable for entities that we can actively modify. While implicit optimistic locking is a widespread technique, few happen to understand the inner workings of explicit optimistic lock mode. Explicit optimistic locking may prevent data integrity anomalies when the locked entities are always modified by some external mechanism.

Logical vs physical clock optimistic locking

Introduction In this article, I’m going to explain how logical and physical clock versioning strategies work and why you should prefer using logical clocks for concurrency control. Optimistic locking is a viable solution for preventing lost updates when running application-level transactions. Optimistic locking requires a version column that can be represented as: a physical clock (a timestamp value taken from the system clock) a logical clock (an incrementing numeric value) This article will demonstrate why logical clocks are better suited for optimistic locking mechanisms. System time The system time is provided by… Read More