Java Persistence API comes with a thorough concurrency control mechanism, supporting both implicit and explicit locking. The implicit locking mechanism is straightforward and it relies on:
- Optimistic locking: Entity state changes can trigger a version incrementation
- Row-level locking: Based on the current running transaction isolation level, the INSERT/UPDATE/DELETE statements may acquire exclusive row locks
While implicit locking is suitable for many scenarios, an explicit locking mechanism can leverage a finer-grained concurrency control.
In my previous posts, I covered the explicit optimistic lock modes:
In this post, I am going to unravel the explicit pessimistic lock modes: