{"record":{"id":"8e256cef1b8075d1","repo":"hibernate/hibernate-orm","slug":"no-collection-for-replacement-found-role","errorCode":null,"errorMessage":"No collection for replacement found: {role}","messagePattern":"No collection for replacement found: (.+?)","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java","lineNumber":1060,"sourceCode":"\t\t\tthrow new HibernateException( \"Replacement of not directly accessible collection found: \"\n\t\t\t\t\t\t\t\t\t\t\t+ oldCollection.getRole() );\n\t\t}\n\t\tassert !collection.isDirectlyAccessible();\n\t\tfinal var oldEntry = collectionEntries.remove( oldCollection.$$_hibernate_getInstanceId(), oldCollection );\n\t\tfinal var entry =\n\t\t\t\toldEntry.getLoadedPersister() != null\n\t\t\t\t\t\t// This is an already existing/loaded collection so ensure the loadedPersister is initialized\n\t\t\t\t\t\t? new CollectionEntry( collection, session.getFactory() )\n\t\t\t\t\t\t// A newly wrapped collection\n\t\t\t\t\t\t: new CollectionEntry( persister, collection );\n\t\tentry.setReadOnly( oldEntry.isReadOnly(), collection );\n\t\tputCollectionEntry( collection, entry );\n\t\tfinal Object key = collection.getKey();\n\t\tif ( key != null ) {\n\t\t\tfinal var collectionKey = session.generateCollectionKey( entry.getLoadedPersister(), key );\n\t\t\tfinal var old = addCollectionByKey( collectionKey, collection );\n\t\t\tif ( old == null ) {\n\t\t\t\tthrow new HibernateException( \"No collection for replacement found: \" + collectionKey.getRole() );\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Add a collection to the cache, with a given collection entry.\n\t *\n\t * @param coll The collection for which we are adding an entry.\n\t * @param entry The entry representing the collection.\n\t * @param key The key of the collection's entry.\n\t */\n\tprivate void addCollection(PersistentCollection<?> coll, CollectionEntry entry, Object key) {\n\t\tputCollectionEntry( coll, entry );\n\t\tfinal var collectionKey = session.generateCollectionKey( entry.getLoadedPersister(), key );\n\t\tfinal var old = addCollectionByKey( collectionKey, coll );\n\t\tif ( old != null ) {\n\t\t\tif ( old == coll ) {\n\t\t\t\tthrow new AssertionFailure( \"bug adding collection twice\" );","sourceCodeStart":1042,"sourceCodeEnd":1078,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java#L1042-L1078","documentation":"Error \"No collection for replacement found: {role}\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown at hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java:1060 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the collection with the given role is loaded in the persistence context before attempting replacement","Verify the role name matches a mapped collection"],"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"}