From 9591bbb1851785f6df9231fe57c5856e906aef4a Mon Sep 17 00:00:00 2001 From: Chris Cranford Date: Sun, 7 Mar 2021 16:54:53 -0500 Subject: [PATCH] Fix NPE with DelayedCollectionInitializer Since the collectionInstance has not been resolved when asked to resolve the collection key, provided an overridden method to not register the resolution listener to avoid the NPE. --- .../internal/DelayedCollectionInitializer.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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 + ); + } + } }