HHH-14499 Explicitly listing mapped classes which are @MappedSuperClass might break narrowing down of generics

This commit is contained in:
Andrea Boriero 2021-03-11 20:52:35 +01:00 committed by Sanne Grinovero
parent 394d6ab2d4
commit 9f22dafe17
1 changed files with 21 additions and 9 deletions

View File

@ -252,7 +252,7 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc
}
private List<XClass> orderAndFillHierarchy(List<XClass> original) {
List<XClass> copy = new ArrayList<XClass>( original );
List<XClass> copy = new ArrayList<>( original.size() );
insertMappedSuperclasses( original, copy );
// order the hierarchy
@ -266,16 +266,28 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc
}
private void insertMappedSuperclasses(List<XClass> original, List<XClass> copy) {
final boolean debug = log.isDebugEnabled();
for ( XClass clazz : original ) {
XClass superClass = clazz.getSuperclass();
while ( superClass != null
&& !reflectionManager.equals( superClass, Object.class )
&& !copy.contains( superClass ) ) {
if ( superClass.isAnnotationPresent( Entity.class )
|| superClass.isAnnotationPresent( javax.persistence.MappedSuperclass.class ) ) {
copy.add( superClass );
if ( clazz.isAnnotationPresent( javax.persistence.MappedSuperclass.class ) ) {
if ( debug ) {
log.debugf(
"Skipping explicit MappedSuperclass %s, the class will be discovered analyzing the implementing class",
clazz
);
}
}
else {
copy.add( clazz );
XClass superClass = clazz.getSuperclass();
while ( superClass != null
&& !reflectionManager.equals( superClass, Object.class )
&& !copy.contains( superClass ) ) {
if ( superClass.isAnnotationPresent( Entity.class )
|| superClass.isAnnotationPresent( javax.persistence.MappedSuperclass.class ) ) {
copy.add( superClass );
}
superClass = superClass.getSuperclass();
}
superClass = superClass.getSuperclass();
}
}
}