{"record":{"id":"3fc74ac8dc1352be","repo":"hibernate/hibernate-orm","slug":"could-not-locate-entityentry-for-the-collection-ow","errorCode":null,"errorMessage":"Could not locate EntityEntry for the collection owner in the PersistenceContext","messagePattern":"Could not locate EntityEntry for the collection owner in the PersistenceContext","errorType":"exception","errorClass":"LazyInitializationException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java","lineNumber":1652,"sourceCode":"\t\t// see if there is already a collection instance associated with the session\n\t\t// NOTE: can this ever happen?\n\t\tfinal var collection = getCollection( entity, collectionType, session, persister );\n\n\t\tfinal var interceptor = asPersistentAttributeInterceptable( entity ).$$_hibernate_getInterceptor();\n\t\tassert interceptor != null : \"Expecting bytecode interceptor to be non-null\";\n\t\tinterceptor.attributeInitialized( fieldName );\n\n\t\tfinal var persistenceContext = session.getPersistenceContextInternal();\n\t\tif ( collectionType.isArrayType() ) {\n\t\t\tpersistenceContext.addCollectionHolder( collection );\n\t\t}\n\t\t// update the \"state\" of the owning entity's EntityEntry to overwrite the\n\t\t// UNFETCHED_PROPERTY for the collection to the just-loaded collection\n\t\tfinal var ownerEntry = persistenceContext.getEntry( entity );\n\t\tif ( ownerEntry == null ) {\n\t\t\t// the entity is not in the session; it was probably deleted,\n\t\t\t// so we cannot load the collection anymore.\n\t\t\tthrow new LazyInitializationException(\n\t\t\t\t\t\"Could not locate EntityEntry for the collection owner in the PersistenceContext\"\n\t\t\t);\n\t\t}\n\t\townerEntry.overwriteLoadedStateCollectionValue( fieldName, collection );\n\n\t\treturn collection;\n\t}\n\n\tprivate static PersistentCollection<?> getCollection(\n\t\t\tObject entity,\n\t\t\tCollectionType collectionType,\n\t\t\tSharedSessionContractImplementor session,\n\t\t\tCollectionPersister persister) {\n\t\tfinal var persistenceContext = session.getPersistenceContextInternal();\n\t\tfinal var entry = persistenceContext.getEntry( entity );\n\t\tfinal Object key = getCollectionKey( persister, entity, entry, session );\n\t\tassert key != null;\n\t\tfinal var collection = persistenceContext.getCollection( session.generateCollectionKey( persister, key ) );","sourceCodeStart":1634,"sourceCodeEnd":1670,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java#L1634-L1670","documentation":"Error \"Could not locate EntityEntry for the collection owner in the PersistenceContext\" thrown in hibernate/hibernate-orm.","triggerScenarios":"Thrown during collection processing when the persistence context has no EntityEntry for the collection's owner entity.","commonSituations":"See trigger scenarios.","solutions":["Load the collection through its managed owner within the same session; avoid operating on collections whose owner was evicted or loaded elsewhere."],"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"}