From 6f96ce41d1ce78b10b5efdfe8ca82b0be3fef108 Mon Sep 17 00:00:00 2001 From: Marco Belladelli Date: Tue, 1 Aug 2023 14:01:37 +0200 Subject: [PATCH] HHH-16755 Consider inherited properties when handling generics --- .../boot/model/internal/ClassPropertyHolder.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ClassPropertyHolder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ClassPropertyHolder.java index 84f791146d..c2fd57c7f0 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ClassPropertyHolder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ClassPropertyHolder.java @@ -6,8 +6,10 @@ */ package org.hibernate.boot.model.internal; +import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.function.Consumer; @@ -302,7 +304,7 @@ public class ClassPropertyHolder extends AbstractPropertyHolder { // because the given XClass has a TypeEnvironment based on the type variable assignments of a subclass // and that might result in a wrong property type being used for a property which uses a type variable final XClass actualDeclaringClass = context.getBootstrapContext().getReflectionManager().toXClass( type ); - for ( XProperty declaredProperty : actualDeclaringClass.getDeclaredProperties( prop.getPropertyAccessorName() ) ) { + for ( XProperty declaredProperty : getDeclaredProperties( actualDeclaringClass, prop.getPropertyAccessorName() ) ) { if ( prop.getName().equals( declaredProperty.getName() ) ) { final PropertyData inferredData = new PropertyInferredData( actualDeclaringClass, @@ -381,6 +383,16 @@ public class ClassPropertyHolder extends AbstractPropertyHolder { } } + private static List getDeclaredProperties(XClass declaringClass, String accessType) { + final List properties = new ArrayList<>(); + XClass superclass = declaringClass; + while ( superclass != null ) { + properties.addAll( superclass.getDeclaredProperties( accessType ) ); + superclass = superclass.getSuperclass(); + } + return properties; + } + private static String getTypeName(Property property) { final String typeName = getTypeName( property.getValue() ); return typeName != null ? typeName : property.getReturnedClassName();