diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/collection/internal/DelayedCollectionInitializer.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/collection/internal/DelayedCollectionInitializer.java index 3dde0ef6ce..c3a4765163 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/collection/internal/DelayedCollectionInitializer.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/collection/internal/DelayedCollectionInitializer.java @@ -8,6 +8,7 @@ package org.hibernate.sql.results.graph.collection.internal; import org.hibernate.collection.spi.CollectionSemantics; import org.hibernate.collection.spi.PersistentCollection; +import org.hibernate.engine.spi.CollectionKey; import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.internal.log.LoggingHelper; @@ -94,4 +95,20 @@ public class DelayedCollectionInitializer extends AbstractCollectionInitializer super.finishUpRow( rowProcessingState ); collectionInstance = null; } + + @Override + public void resolveKey(RowProcessingState rowProcessingState) { + if ( collectionKey != null ) { + // already resolved + return; + } + + final Object parentKey = parentAccess.getParentKey(); + if ( parentKey != null ) { + collectionKey = new CollectionKey( + collectionAttributeMapping.getCollectionDescriptor(), + parentKey + ); + } + } }