From 4f92a5b379b41befc3f699051aaf1fa623d24aa2 Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Wed, 3 Apr 2024 16:22:40 +0200 Subject: [PATCH] HHH-17885 Fix for same named attribute of different Embedded uses same selection expression --- .../mapping/internal/AbstractEmbeddableMapping.java | 10 +++++++++- .../mapping/internal/EmbeddableMappingTypeImpl.java | 2 +- .../metamodel/model/domain/NavigableRole.java | 4 ---- 3 files changed, 10 insertions(+), 6 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 7773c46f36..e1d0b3b8be 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 @@ -305,7 +305,7 @@ public abstract class AbstractEmbeddableMapping implements EmbeddableMappingType temporalPrecision = null; nullable = true; isLob = false; - selectablePath = basicValue.createSelectablePath( bootPropertyDescriptor.getName() ); + selectablePath = new SelectablePath( determineEmbeddablePrefix() + bootPropertyDescriptor.getName() ); } attributeMapping = MappingModelCreationHelper.buildBasicAttributeMapping( @@ -457,6 +457,14 @@ public abstract class AbstractEmbeddableMapping implements EmbeddableMappingType return true; } + protected String determineEmbeddablePrefix() { + NavigableRole root = getNavigableRole().getParent(); + while ( !root.isRoot() ) { + root = root.getParent(); + } + return getNavigableRole().getFullPath().substring( root.getFullPath().length() + 1 ) + "."; + } + @Override public int getNumberOfFetchables() { return getAttributeMappings().size(); 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 b30804f0b4..b5a0f198e1 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 @@ -403,7 +403,7 @@ public class EmbeddableMappingTypeImpl extends AbstractEmbeddableMapping impleme temporalPrecision = null; isLob = false; nullable = bootPropertyDescriptor.isOptional(); - selectablePath = basicValue.createSelectablePath( bootPropertyDescriptor.getName() ); + selectablePath = new SelectablePath( determineEmbeddablePrefix() + bootPropertyDescriptor.getName() ); } attributeMapping = MappingModelCreationHelper.buildBasicAttributeMapping( bootPropertyDescriptor.getName(), diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/NavigableRole.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/NavigableRole.java index f6e5125912..8e3dab06e7 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/NavigableRole.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/NavigableRole.java @@ -106,10 +106,6 @@ public final class NavigableRole implements DotIdentifierSequence, Serializable return fullPath; } - public boolean isRoot() { - return parent == null && StringHelper.isEmpty( localName ); - } - @Override public String toString() { return getClass().getSimpleName() + '[' + fullPath + ']';