Optimistic lock conflict: OptimisticLockException / StaleObjectStateException / version mismatch
Someone else changed the record after you read it, so your update — based on an old version — was rejected to avoid overwriting their change.
Row was updated or deleted by another transactionVersionError: No matching document foundversion conflict Meaning
Optimistic locking stores a version number or ETag with each record. An update must say which version it was based on; if the stored version has moved on, the write fails instead of silently losing the other change.
JPA/Hibernate throws OptimisticLockException or StaleObjectStateException (“Row was updated or deleted by another transaction”), Spring wraps it as ObjectOptimisticLockingFailureException, Mongoose throws VersionError, and REST APIs answer 409 Conflict or 412 Precondition Failed.
Common causes
- Two users or workers edited the same record concurrently
- Client kept an old copy and submitted it much later
- Retry logic re-sent an update with a stale version
- Background job updates the row while a user edits it
⚡ Quick fix
- Re-read the latest record, merge the user’s change, and retry with the new version
- Show users a “this record changed” message instead of overwriting
- Retry automatically only for idempotent, mergeable changes
Detailed fix by platform
Java
- java
@Version private Long version; // JPA entity try { repo.save(entity); } catch (ObjectOptimisticLockingFailureException e) { /* reload, merge, retry or tell the user */ }
Node.js
- javascript
// Mongoose: VersionError — reload and re-apply const doc = await Model.findById(id); doc.set(changes); await doc.save();
REST API
curl -X PUT https://api.example.com/v1/items/42 -H 'If-Match: "v7"' -d @item.json # send the current ETag/version
How to diagnose
- Versions — Requested vs current version/ETag
- Writers — Which other process updated the record?
- Retry — Does the client resend stale data?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in API
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 12 Oct 2026