Skip to content

Commit

Permalink
HHH-14257 An Entity A with a map collection having as index an Embedd…
Browse files Browse the repository at this point in the history
…able with a an association to the Entity A fails with a NPE
  • Loading branch information
dreab8 authored and Sanne committed Nov 16, 2020
1 parent bf0b86d commit 00b3ccb
Showing 1 changed file with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -666,23 +666,30 @@ public void foundCircularAssociation(AssociationAttributeDefinition attributeDef

// 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 {
Expand Down

0 comments on commit 00b3ccb

Please sign in to comment.