intermediateTop 30 Scenario-Based Questions
How do you implement optimistic locking in a Spring Boot application with JPA?
JPA @Version annotation: @Entity public class Order { @Id Long id; @Version Integer version; ... }. JPA auto-handles: on UPDATE, includes AND version = :current in the WHERE clause. On 0 rows updated: throws OptimisticLockException (DataAccessException in Spring). SQL generated: UPDATE orders SET ... version = version+1 WHERE id = ? AND version = ?. Spring retry: @Retryable(value=OptimisticLockExc
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a response