Skip to content

Commit 00b3ccb

Browse files
dreab8Sanne
authored andcommitted
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
1 parent bf0b86d commit 00b3ccb

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

hibernate-core/src/main/java/org/hibernate/loader/plan/build/internal/AbstractLoadPlanBuildingAssociationVisitationStrategy.java

+23-16
Original file line numberDiff line numberDiff line change
@@ -666,23 +666,30 @@ public void foundCircularAssociation(AssociationAttributeDefinition attributeDef
666666

667667
// go ahead and build the bidirectional fetch
668668
if ( attributeDefinition.getAssociationNature() == AssociationAttributeDefinition.AssociationNature.ENTITY ) {
669-
final Joinable currentEntityPersister = (Joinable) currentSource().resolveEntityReference().getEntityPersister();
670-
final AssociationKey currentEntityReferenceAssociationKey =
671-
new AssociationKey( currentEntityPersister.getTableName(), currentEntityPersister.getKeyColumnNames() );
672-
// if associationKey is equal to currentEntityReferenceAssociationKey
673-
// that means that the current EntityPersister has a single primary key attribute
674-
// (i.e., derived attribute) which is mapped by attributeDefinition.
675-
// This is not a bidirectional association.
676-
// TODO: AFAICT, to avoid an overflow, the associated entity must already be loaded into the session, or
677-
// it must be loaded when the ID for the dependent entity is resolved. Is there some other way to
678-
// deal with this???
679669
final FetchSource registeredFetchSource = registeredFetchSource( associationKey );
680-
if ( registeredFetchSource != null && ! associationKey.equals( currentEntityReferenceAssociationKey ) ) {
681-
currentSource().buildBidirectionalEntityReference(
682-
attributeDefinition,
683-
fetchStrategy,
684-
registeredFetchSource( associationKey ).resolveEntityReference()
685-
);
670+
if ( registeredFetchSource != null ) {
671+
final ExpandingFetchSource currentSource = currentSource();
672+
final Joinable currentEntityPersister = (Joinable) currentSource.resolveEntityReference().getEntityPersister();
673+
674+
final AssociationKey currentEntityReferenceAssociationKey =
675+
new AssociationKey( currentEntityPersister.getTableName(), currentEntityPersister.getKeyColumnNames() );
676+
// if associationKey is equal to currentEntityReferenceAssociationKey
677+
// that means that the current EntityPersister has a single primary key attribute
678+
// (i.e., derived attribute) which is mapped by attributeDefinition.
679+
// This is not a bidirectional association.
680+
// TODO: AFAICT, to avoid an overflow, the associated entity must already be loaded into the session, or
681+
// it must be loaded when the ID for the dependent entity is resolved. Is there some other way to
682+
// deal with this???
683+
if ( !associationKey.equals( currentEntityReferenceAssociationKey ) ) {
684+
currentSource.buildBidirectionalEntityReference(
685+
attributeDefinition,
686+
fetchStrategy,
687+
registeredFetchSource.resolveEntityReference()
688+
);
689+
}
690+
}
691+
else {
692+
// Do nothing, no bi-directionality
686693
}
687694
}
688695
else {

0 commit comments

Comments
 (0)