What is optimistic locking in JPA, and how does @Version implement it?
Advanced Spring Data JPA
Optimistic locking assumes concurrent update conflicts are rare and avoids taking a database lock during a transaction — instead, an entity carries a `@Version` field (an int or timestamp) that Hibernate automatically increments on every update, and includes the version in the WHERE clause of the UPDATE statement. If another transaction already changed the row (and its version) since it was read, the affected-row count comes back zero and Hibernate throws an OptimisticLockException, letting the application detect and handle the conflict instead of silently overwriting the other transaction's change.

