intermediateConcurrency — Optimistic & Pessimistic Locking, MVCC

How does @Version implement optimistic locking under the hood?

Hibernate includes the loaded version value in the generated UPDATE's WHERE clause and increments it on write. If another transaction already updated (and bumped the version of) the same row, the WHERE clause matches zero rows — Hibernate detects this via the affected-row count and throws OptimisticLockException.

This is a Pro chapter

Sign in, then upgrade to Pro or Power to unlock this and the full Spring Ecosystem Mastery library.

How does @Version implement optimistic locking under the hood?

Next Step

Continue to When would you choose pessimistic locking over optimistic locking?← Back to all Spring Data JPA & Hibernate Mastery questions