From 46e3c542712c713226dda5c2c9a642e7122ef742 Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Wed, 15 Mar 2023 16:36:20 +0100 Subject: [PATCH] HHH-16166 Correct Plural and ToOne attribute mapping declaring types --- .../mapping/internal/AbstractEmbeddableMapping.java | 7 ++----- .../mapping/internal/EmbeddableMappingTypeImpl.java | 6 ++---- .../mapping/internal/MappingModelCreationHelper.java | 2 +- .../java/org/hibernate/sql/results/graph/Initializer.java | 3 ++- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEmbeddableMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEmbeddableMapping.java index 120a23db3b..84cc56d36a 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEmbeddableMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AbstractEmbeddableMapping.java @@ -397,15 +397,12 @@ public abstract class AbstractEmbeddableMapping implements EmbeddableMappingType columnPosition += columnSpan; } else if ( subtype instanceof CollectionType ) { - final EntityPersister entityPersister = creationProcess.getEntityPersister( bootDescriptor.getOwner() - .getEntityName() ); - attributeMapping = MappingModelCreationHelper.buildPluralAttributeMapping( bootPropertyDescriptor.getName(), attributeIndex, attributeIndex, bootPropertyDescriptor, - entityPersister, + this, propertyAccess, compositeType.getCascadeStyle( attributeIndex ), compositeType.getFetchMode( attributeIndex ), @@ -422,7 +419,7 @@ public abstract class AbstractEmbeddableMapping implements EmbeddableMappingType attributeIndex, attributeIndex, bootPropertyDescriptor, - entityPersister, + this, entityPersister, (EntityType) subtype, representationStrategy.resolvePropertyAccess( bootPropertyDescriptor ), diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddableMappingTypeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddableMappingTypeImpl.java index 478b3b7b27..1ac1360c4a 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddableMappingTypeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddableMappingTypeImpl.java @@ -496,14 +496,12 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme columnPosition += columnSpan; } else if ( subtype instanceof CollectionType ) { - final EntityPersister entityPersister = creationProcess.getEntityPersister( bootDescriptor.getOwner().getEntityName() ); - attributeMapping = MappingModelCreationHelper.buildPluralAttributeMapping( bootPropertyDescriptor.getName(), attributeIndex, attributeIndex, bootPropertyDescriptor, - entityPersister, + this, representationStrategy.resolvePropertyAccess( bootPropertyDescriptor ), compositeType.getCascadeStyle( attributeIndex), compositeType.getFetchMode( attributeIndex ), @@ -519,7 +517,7 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme attributeIndex, attributeIndex, bootPropertyDescriptor, - entityPersister, + this, entityPersister, (EntityType) subtype, getRepresentationStrategy().resolvePropertyAccess( bootPropertyDescriptor ), diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java index 18bf541428..06c239a9ad 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/MappingModelCreationHelper.java @@ -718,7 +718,7 @@ public class MappingModelCreationHelper { fkTargetPart = collectionDescriptor.getOwnerEntityPersister().getIdentifierMapping(); } else { - fkTargetPart = declaringType.findAttributeMapping( lhsPropertyName ); + fkTargetPart = declaringType.findContainingEntityMapping().findAttributeMapping( lhsPropertyName ); } if ( keyType instanceof BasicType ) { diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/Initializer.java b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/Initializer.java index f95e0fcb5b..6fd45e454f 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/graph/Initializer.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/graph/Initializer.java @@ -84,7 +84,8 @@ public interface Initializer { if ( entityInitializer != null ) { final EntityPersister concreteDescriptor = entityInitializer.getConcreteDescriptor(); if ( concreteDescriptor.getEntityMetamodel().isPolymorphic() ) { - final EntityPersister declaringType = (EntityPersister) referencedModelPart.getDeclaringType(); + final EntityPersister declaringType = (EntityPersister) referencedModelPart.getDeclaringType() + .findContainingEntityMapping(); if ( concreteDescriptor != declaringType ) { return declaringType.getSubclassEntityNames().contains( concreteDescriptor.getEntityName() ); }