{"record":{"id":"19a131cbced958bb","repo":"hibernate/hibernate-orm","slug":"collection-role-was-not-processed-by-flush-t","errorCode":null,"errorMessage":"Collection '${role}' was not processed by flush (this is likely due to unsafe use of the session, for example, current use in multiple threads, or updates during entity lifecycle callbacks)","messagePattern":"Collection '(.+?)' was not processed by flush \\(this is likely due to unsafe use of the session, for example, current use in multiple threads, or updates during entity lifecycle callbacks\\)","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/engine/spi/CollectionEntry.java","lineNumber":209,"sourceCode":"\t}\n\n\tpublic void postInitialize(PersistentCollection<?> collection, SharedSessionContractImplementor session) {\n\t\tfinal var loadedPersister = this.loadedPersister;\n\t\tsnapshot = loadedPersister != null && isModifiable() ? collection.getSnapshot( loadedPersister ) : null;\n\t\tcollection.setSnapshot( loadedKey, role, snapshot );\n\t\tif ( loadedPersister != null\n\t\t\t\t&& session.getLoadQueryInfluencers().effectivelyBatchLoadable( loadedPersister ) ) {\n\t\t\tsession.getPersistenceContextInternal().getBatchFetchQueue()\n\t\t\t\t\t.removeBatchLoadableCollection( this );\n\t\t}\n\t}\n\n\t/**\n\t * Called after a successful flush\n\t */\n\tpublic void postFlush(PersistentCollection<?> collection, CollectionFlushActionTracker collectionFlushActionTracker) {\n\t\tif ( !ignore && !collectionFlushActionTracker.wasCollectionProcessed( collection ) ) {\n\t\t\tthrow new HibernateException( \"Collection '\" + collection.getRole() + \"' was not processed by flush\"\n\t\t\t\t\t+ \" (this is likely due to unsafe use of the session, for example, current use in multiple threads, or updates during entity lifecycle callbacks)\");\n\t\t}\n\t\tignore = false;\n\t\tcollection.setSnapshot( loadedKey, role, snapshot );\n\t}\n\n\t/**\n\t * Called after execution of an action\n\t */\n\tpublic void afterAction(PersistentCollection<?> collection) {\n\t\tloadedKey = currentKey;\n\t\tloadedPersister = currentPersister;\n\t\trole = currentPersister == null ? null : currentPersister.getRole();\n\t\tif ( collection.wasInitialized()\n\t\t\t\t&& hasQueuedCollectionAction( collection ) ) {\n\t\t\t// update the snapshot\n\t\t\tsnapshot = isModifiable()\n\t\t\t\t\t? collection.getSnapshot( castNonNull( loadedPersister ) )","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/engine/spi/CollectionEntry.java#L191-L227","documentation":"Error \"Collection '${role}' was not processed by flush (this is likely due to unsafe use of the session, for example, current use in multiple threads, or updates during entity lifecycle callbacks)\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown at hibernate-core/src/main/java/org/hibernate/engine/spi/CollectionEntry.java:209 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use the session from a single thread only and avoid concurrent access","Do not modify entities inside lifecycle callbacks in ways that bypass flush processing","Ensure flush completes before the collection is accessed again"],"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"}