From 9aabaf1220de0368bbd0a29decd866dc0c1ac83f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Tue, 13 Sep 2022 17:00:59 +0200 Subject: [PATCH] HHH-15505 Fix bytecode enhancement on entity whose field is defined both in mapped superclass and concrete entity --- .../bytebuddy/PersistentAttributeTransformer.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/internal/bytebuddy/PersistentAttributeTransformer.java b/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/internal/bytebuddy/PersistentAttributeTransformer.java index 6d62c10c30..c45381d9f6 100644 --- a/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/internal/bytebuddy/PersistentAttributeTransformer.java +++ b/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/internal/bytebuddy/PersistentAttributeTransformer.java @@ -91,6 +91,12 @@ final class PersistentAttributeTransformer implements AsmVisitorWrapper.ForDecla ByteBuddyEnhancementContext enhancementContext, TypePool classPool) { List 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() ) {