{"record":{"id":"3bf3b2d485dc5547","repo":"hibernate/hibernate-orm","slug":"immutable-collection-was-modified-collectioninf","errorCode":null,"errorMessage":"Immutable collection was modified: ${collectionInfo}","messagePattern":"Immutable collection was modified: (.+?)","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/engine/spi/CollectionEntry.java","lineNumber":179,"sourceCode":"\t\t\t|| loadedPersister.getElementType().isMutable();\n\t}\n\n\tprivate boolean isModifiable() {\n\t\treturn !readOnly\n\t\t\t&& loadedPersister != null\n\t\t\t&& loadedPersister.isMutable();\n\t}\n\n\tpublic void preFlush(PersistentCollection<?> collection) {\n\t\tif ( loadedKey == null ) {\n\t\t\tloadedKey = collection.getKey();\n\t\t}\n\n\t\tfinal var loadedPersister = this.loadedPersister;\n\t\tif ( collection.isDirty()\n\t\t\t\t&& loadedPersister != null\n\t\t\t\t&& !isModifiable() ) {\n\t\t\tthrow new HibernateException( \"Immutable collection was modified: \" +\n\t\t\t\t\tcollectionInfoString( loadedPersister.getRole(), getLoadedKey() ) );\n\t\t}\n\n\t\tdirty( collection );\n\n\t\tif ( CORE_LOGGER.isTraceEnabled()\n\t\t\t\t&& loadedPersister != null\n\t\t\t\t&& collection.isDirty() ) {\n\t\t\tCORE_LOGGER.collectionDirty(\n\t\t\t\t\tcollectionInfoString( loadedPersister.getRole(), getLoadedKey() ) );\n\t\t}\n\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","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/engine/spi/CollectionEntry.java#L161-L197","documentation":"Error \"Immutable collection was modified: ${collectionInfo}\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown at hibernate-core/src/main/java/org/hibernate/engine/spi/CollectionEntry.java:179 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Do not modify a collection mapped as immutable; replace it or make the mapping mutable","Remove the immutability restriction from the collection mapping"],"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"}