HHH-16755 Consider inherited properties when handling generics

This commit is contained in:
Marco Belladelli 2023-08-01 14:01:37 +02:00
parent 8ab82f1401
commit 6f96ce41d1
1 changed files with 13 additions and 1 deletions

View File

@ -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<XProperty> getDeclaredProperties(XClass declaringClass, String accessType) {
final List<XProperty> 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();