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.
This commit is contained in:
Chris Cranford 2021-03-07 16:54:53 -05:00 committed by Andrea Boriero
parent 79d2569618
commit 9591bbb185
1 changed files with 17 additions and 0 deletions

View File

@ -8,6 +8,7 @@ package org.hibernate.sql.results.graph.collection.internal;
import org.hibernate.collection.spi.CollectionSemantics; import org.hibernate.collection.spi.CollectionSemantics;
import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.engine.spi.CollectionKey;
import org.hibernate.engine.spi.PersistenceContext; import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.internal.log.LoggingHelper; import org.hibernate.internal.log.LoggingHelper;
@ -94,4 +95,20 @@ public class DelayedCollectionInitializer extends AbstractCollectionInitializer
super.finishUpRow( rowProcessingState ); super.finishUpRow( rowProcessingState );
collectionInstance = null; 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
);
}
}
} }