HHH-15505 Fix bytecode enhancement on entity whose field is defined both in mapped superclass and concrete entity

This commit is contained in:
Yoann Rodière 2022-09-13 17:00:59 +02:00
parent 62ff89414b
commit 9aabaf1220
1 changed files with 6 additions and 5 deletions

View File

@ -91,6 +91,12 @@ final class PersistentAttributeTransformer implements AsmVisitorWrapper.ForDecla
ByteBuddyEnhancementContext enhancementContext,
TypePool classPool) {
List<AnnotatedFieldDescription> persistentFieldList = new ArrayList<>();
// HHH-10646 Add fields inherited from @MappedSuperclass
// HHH-10981 There is no need to do it for @MappedSuperclass
// HHH-15505 This needs to be done first so that fields with the same name in the mappedsuperclass and entity are handled correctly
if ( !enhancementContext.isMappedSuperclassClass( managedCtClass ) ) {
persistentFieldList.addAll( collectInheritPersistentFields( managedCtClass, enhancementContext ) );
}
for ( FieldDescription ctField : managedCtClass.getDeclaredFields() ) {
// skip static fields and skip fields added by enhancement and outer reference in inner classes
if ( ctField.getName().startsWith( "$$_hibernate_" ) || "this$0".equals( ctField.getName() ) ) {
@ -101,11 +107,6 @@ final class PersistentAttributeTransformer implements AsmVisitorWrapper.ForDecla
persistentFieldList.add( annotatedField );
}
}
// HHH-10646 Add fields inherited from @MappedSuperclass
// HHH-10981 There is no need to do it for @MappedSuperclass
if ( !enhancementContext.isMappedSuperclassClass( managedCtClass ) ) {
persistentFieldList.addAll( collectInheritPersistentFields( managedCtClass, enhancementContext ) );
}
AnnotatedFieldDescription[] orderedFields = enhancementContext.order( persistentFieldList.toArray( new AnnotatedFieldDescription[0] ) );
if ( log.isDebugEnabled() ) {