hibernate/hibernate-orm · error · LazyInitializationException
Could not locate EntityEntry for the collection owner in the
Error message
Could not locate EntityEntry for the collection owner in the PersistenceContext
What it means
Error "Could not locate EntityEntry for the collection owner in the PersistenceContext" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java:1652
// see if there is already a collection instance associated with the session
// NOTE: can this ever happen?
final var collection = getCollection( entity, collectionType, session, persister );
final var interceptor = asPersistentAttributeInterceptable( entity ).$$_hibernate_getInterceptor();
assert interceptor != null : "Expecting bytecode interceptor to be non-null";
interceptor.attributeInitialized( fieldName );
final var persistenceContext = session.getPersistenceContextInternal();
if ( collectionType.isArrayType() ) {
persistenceContext.addCollectionHolder( collection );
}
// update the "state" of the owning entity's EntityEntry to overwrite the
// UNFETCHED_PROPERTY for the collection to the just-loaded collection
final var ownerEntry = persistenceContext.getEntry( entity );
if ( ownerEntry == null ) {
// the entity is not in the session; it was probably deleted,
// so we cannot load the collection anymore.
throw new LazyInitializationException(
"Could not locate EntityEntry for the collection owner in the PersistenceContext"
);
}
ownerEntry.overwriteLoadedStateCollectionValue( fieldName, collection );
return collection;
}
private static PersistentCollection<?> getCollection(
Object entity,
CollectionType collectionType,
SharedSessionContractImplementor session,
CollectionPersister persister) {
final var persistenceContext = session.getPersistenceContextInternal();
final var entry = persistenceContext.getEntry( entity );
final Object key = getCollectionKey( persister, entity, entry, session );
assert key != null;
final var collection = persistenceContext.getCollection( session.generateCollectionKey( persister, key ) );View on GitHub (pinned to fad1729dce)
Solutions
- Load the collection through its managed owner within the same session; avoid operating on collections whose owner was evicted or loaded elsewhere.
When it happens
Trigger: Thrown during collection processing when the persistence context has no EntityEntry for the collection's owner entity.
Common situations: See trigger scenarios.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/3fc74ac8dc1352be.
Report an issue: GitHub.