Skip to content
Ameen Abozaid
Planned lessonMID-016-L06

Demo: concurrent edits with @Version

  • Lesson 6 of 7
  • Mid-level
On This Lesson 3 topics

This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.

In this lesson

show two admins editing the same product and returning 409.

Draft outline details

Step by step

  1. Add @Version to Product and include version in the response DTO.
  2. Two clients fetch product 1 (version 3).
  3. Client A updates the name with version 3 and succeeds (version 4).
  4. Planned mistake: the update DTO omits the version, so the entity is loaded fresh and the conflict is missed. Fix: require the version in the request and compare it.
  5. Client B updates with version 3: ObjectOptimisticLockingFailureException, mapped by @ControllerAdvice to 409 with the current version.
  6. Write an integration test for the two-client conflict.

Prepares MID-016-LAB1.

Check your understanding

What must the client send back to make optimistic locking work across requests?

Show answer

The version it read.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.