From fc337a92948931c78ac1f2e150827de4aa1b9e60 Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Mon, 26 Aug 2024 11:25:47 +0200 Subject: [PATCH] HHH-18490 Handle "concrete" generic embeddable attributes defined in mapped superclass Also, resolve the correct expressible for function return type resolvers based on argument types. --- .../metamodel/internal/MetadataContext.java | 40 ++++++++++++++++++- .../StandardFunctionReturnTypeResolvers.java | 9 +---- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java index 0634947f3f..ebdb4f9419 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java @@ -26,6 +26,7 @@ import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.collections.CollectionHelper; +import org.hibernate.internal.util.collections.JoinedList; import org.hibernate.mapping.Component; import org.hibernate.mapping.MappedSuperclass; import org.hibernate.mapping.PersistentClass; @@ -60,6 +61,8 @@ import jakarta.persistence.metamodel.IdentifiableType; import jakarta.persistence.metamodel.SingularAttribute; import jakarta.persistence.metamodel.Type; +import static org.hibernate.internal.util.StringHelper.root; + /** * Defines a context for storing information during the building of the {@link MappingMetamodelImpl}. *

@@ -415,7 +418,16 @@ public class MetadataContext { final PersistentAttribute attribute = attributeFactory.buildAttribute( (ManagedDomainType) embeddable, property ); if ( attribute != null ) { - addAttribute( embeddable, attribute ); + final Property superclassProperty = getMappedSuperclassProperty( + property.getName(), + component.getMappedSuperclass() + ); + if ( superclassProperty != null && superclassProperty.isGeneric() ) { + ( (AttributeContainer) embeddable ).getInFlightAccess().addConcreteGenericAttribute( attribute ); + } + else { + addAttribute( embeddable, attribute ); + } } } @@ -643,6 +655,32 @@ public class MetadataContext { : getMappedSuperclass( mappedSuperclass.getSuperPersistentClass() ); } + private Property getMappedSuperclassProperty(String propertyName, MappedSuperclass mappedSuperclass) { + if ( mappedSuperclass == null ) { + return null; + } + + for ( Property property : mappedSuperclass.getDeclaredProperties() ) { + if ( property.getName().equals( propertyName ) ) { + return property; + } + } + + final Property property = getMappedSuperclassProperty( + propertyName, + mappedSuperclass.getSuperMappedSuperclass() + ); + if ( property != null ) { + return property; + } + + if ( mappedSuperclass.getSuperPersistentClass() != null ) { + return mappedSuperclass.getSuperPersistentClass().getProperty( propertyName ); + } + + return null; + } + private Set> buildIdClassAttributes( IdentifiableDomainType ownerType, List properties) { diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/StandardFunctionReturnTypeResolvers.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/StandardFunctionReturnTypeResolvers.java index ec94119941..eca56d466d 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/StandardFunctionReturnTypeResolvers.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/function/StandardFunctionReturnTypeResolvers.java @@ -241,13 +241,8 @@ public class StandardFunctionReturnTypeResolvers { } private static SqmExpressible getArgumentExpressible(SqmTypedNode specifiedArgument) { - final SqmExpressible expressible = specifiedArgument.getNodeType(); - final SqmExpressible specifiedArgType = expressible instanceof SqmTypedNode - ? ( (SqmTypedNode) expressible ).getNodeType() - : expressible; - return specifiedArgType instanceof SqmPathSource - ? ( (SqmPathSource) specifiedArgType ).getSqmPathType() - : specifiedArgType; + final SqmExpressible expressible = specifiedArgument.getExpressible(); + return expressible != null ? expressible.getSqmType() : null; } public static JdbcMapping extractArgumentJdbcMapping(