{"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":"Internal invariant failure during lazy collection initialization: the session's persistence context holds the collection but has no EntityEntry for the collection's owner entity, so Hibernate cannot determine the owner's state needed to finish initialization. This indicates corrupted or unusual persistence-context state (owner evicted while its collection remains), not a user input error.","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":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}