HHH-14257 An Entity A with a map collection having as index an Embeddable with a an association to the Entity A fails with a NPE

This commit is contained in:
Andrea Boriero 2020-10-15 11:26:54 +01:00 committed by Sanne Grinovero
parent 64aa8ae60a
commit 3d28893d9a
1 changed files with 23 additions and 16 deletions

View File

@ -666,23 +666,30 @@ public abstract class AbstractLoadPlanBuildingAssociationVisitationStrategy
// go ahead and build the bidirectional fetch
if ( attributeDefinition.getAssociationNature() == AssociationAttributeDefinition.AssociationNature.ENTITY ) {
final Joinable currentEntityPersister = (Joinable) currentSource().resolveEntityReference().getEntityPersister();
final AssociationKey currentEntityReferenceAssociationKey =
new AssociationKey( currentEntityPersister.getTableName(), currentEntityPersister.getKeyColumnNames() );
// if associationKey is equal to currentEntityReferenceAssociationKey
// that means that the current EntityPersister has a single primary key attribute
// (i.e., derived attribute) which is mapped by attributeDefinition.
// This is not a bidirectional association.
// TODO: AFAICT, to avoid an overflow, the associated entity must already be loaded into the session, or
// it must be loaded when the ID for the dependent entity is resolved. Is there some other way to
// deal with this???
final FetchSource registeredFetchSource = registeredFetchSource( associationKey );
if ( registeredFetchSource != null && ! associationKey.equals( currentEntityReferenceAssociationKey ) ) {
currentSource().buildBidirectionalEntityReference(
attributeDefinition,
fetchStrategy,
registeredFetchSource( associationKey ).resolveEntityReference()
);
if ( registeredFetchSource != null ) {
final ExpandingFetchSource currentSource = currentSource();
final Joinable currentEntityPersister = (Joinable) currentSource.resolveEntityReference().getEntityPersister();
final AssociationKey currentEntityReferenceAssociationKey =
new AssociationKey( currentEntityPersister.getTableName(), currentEntityPersister.getKeyColumnNames() );
// if associationKey is equal to currentEntityReferenceAssociationKey
// that means that the current EntityPersister has a single primary key attribute
// (i.e., derived attribute) which is mapped by attributeDefinition.
// This is not a bidirectional association.
// TODO: AFAICT, to avoid an overflow, the associated entity must already be loaded into the session, or
// it must be loaded when the ID for the dependent entity is resolved. Is there some other way to
// deal with this???
if ( !associationKey.equals( currentEntityReferenceAssociationKey ) ) {
currentSource.buildBidirectionalEntityReference(
attributeDefinition,
fetchStrategy,
registeredFetchSource.resolveEntityReference()
);
}
}
else {
// Do nothing, no bi-directionality
}
}
else {