PrepZone Logo
PrepZone
Back to Spring Boot

Spring Boot · Hard

What is optimistic locking vs pessimistic locking in JPA?

Spring BootJPA & TransactionsLockingStaffArchitect

Answer preview

Optimistic Locking: Assumes conflicts are rare. Multiple transactions read the same data. Before updating, the version is checked — if it changed since the read, an OptimisticLockException is thrown (the transaction retries or the user is notified). No database locks held during …