{"record":{"id":"799c03a7d18d4b44","repo":"hibernate/hibernate-orm","slug":"row-was-already-updated-or-deleted-by-another-tran-799c03","errorCode":null,"errorMessage":"Row was already updated or deleted by another transaction","messagePattern":"Row was already updated or deleted by another transaction","errorType":"exception","errorClass":"StaleObjectStateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/event/internal/DefaultFlushEntityEventListener.java","lineNumber":758,"sourceCode":"\t\t\t);\n\t\t}\n\t}\n\n\t@Nullable\n\tprivate static Object[] getDatabaseSnapshot(\n\t\t\t@Nonnull EntityPersister persister,\n\t\t\t@Nonnull Object id,\n\t\t\t@Nonnull SessionImplementor session) {\n\t\tfinal var persistenceContext = session.getPersistenceContextInternal();\n\t\tif ( persister.isSelectBeforeUpdateRequired() ) {\n\t\t\tfinal Object[] snapshot = persistenceContext.getDatabaseSnapshot( id, persister );\n\t\t\tif ( snapshot == null ) {\n\t\t\t\t//do we even really need this? the update will fail anyway\n\t\t\t\tfinal var statistics = session.getFactory().getStatistics();\n\t\t\t\tif ( statistics.isStatisticsEnabled() ) {\n\t\t\t\t\tstatistics.optimisticFailure( persister.getEntityName() );\n\t\t\t\t}\n\t\t\t\tthrow new StaleObjectStateException( persister.getEntityName(), id );\n\t\t\t}\n\t\t\treturn snapshot;\n\t\t}\n\t\t// TODO: optimize away this lookup for entities w/o unsaved-value=\"undefined\"\n\t\treturn persistenceContext.getCachedDatabaseSnapshot( session.generateEntityKey( id, persister ) );\n\t}\n}\n","sourceCodeStart":740,"sourceCodeEnd":766,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultFlushEntityEventListener.java#L740-L766","documentation":"Error \"Row was already updated or deleted by another transaction\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown when a flush detects that the database row was concurrently modified or removed by another transaction (stale optimistic state).","commonSituations":"Typical situations: concurrent transactions updating the same row; long-running transactions with optimistic locking; reusing stale entities across transactions.","solutions":["Use optimistic locking (@Version) and catch OptimisticLockException to retry the operation with fresh data.","Reload the entity from the database before modifying it if another transaction may have changed it.","Shorten transaction scope to reduce the window for concurrent modifications."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}