liveBook · Manning

Optimistic locking

As explained in Java Persistence with Spring Data and Hibernate epub

Optimistic locking detects conflicting concurrent modifications by checking an entity version or equivalent state rather than acquiring exclusive locks in advance.

Optimistic locking detects conflicting concurrent modifications by checking an entity version instead of acquiring an exclusive lock in advance. It addresses the risk that concurrent units of work change the same data. section 11.2.1 section 11.0

Figure 11.1 Lost update: Two transactions update the same data without isolation.

The lost-update diagram shows the conflict to look for: two transactions update the same data without sufficient isolation. section 11.2.1

Versioning is one consideration when choosing a database isolation level, not a substitute for that choice. The appropriate level depends on the application scenario: too much isolation can limit scalability, while too little can leave bugs that appear only under heavy load. Avoid read uncommitted for ordinary application use because another transaction can act on changes that are later rolled back. section 11.2.1

How Java Persistence with Spring Data and Hibernate epub covers it

How deep it goes
Identifies versioning and places it in isolation-level decisions, but defers its detailed treatment.
Examples
Uses a diagram of two transactions updating the same data without isolation.
What it assumes
Assumes familiarity with database transactions and introduces versioning without showing an implementation.
What you can do after
Evaluate/understand versioning as one consideration when choosing an isolation level for concurrent application work.
How it connects
Connects to transactions, versioning, lost updates, and database isolation levels.

Also explained in

Compare how 2 books explain optimistic locking →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Java Persistence with Spring Data and Hibernate epub. The section links point to the parts of the book it draws on.