From 2ae61a3e339ae0743e2a3d4558fee8a1100f8724 Mon Sep 17 00:00:00 2001 From: barreiro Date: Tue, 22 Mar 2016 06:20:54 +0000 Subject: [PATCH] HHH-10583 - [enhancer] also consider attribute type when finding the right mappedBy value (cherry picked from commit c33735108a128868023b736893ccf9bfcc37788e) --- .../enhance/internal/PersistentAttributesHelper.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/internal/PersistentAttributesHelper.java b/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/internal/PersistentAttributesHelper.java index 40b7bad697..267b43cc17 100644 --- a/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/internal/PersistentAttributesHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/bytecode/enhance/internal/PersistentAttributesHelper.java @@ -207,7 +207,7 @@ public class PersistentAttributesHelper { PersistentAttributesHelper.hasAnnotation( persistentField, ManyToMany.class ); } - public static String getMappedBy(CtField persistentField, CtClass targetEntity, EnhancementContext context) { + public static String getMappedBy(CtField persistentField, CtClass targetEntity, EnhancementContext context) throws NotFoundException { final String local = getMappedByFromAnnotation( persistentField ); return local.isEmpty() ? getMappedByFromTargetEntity( persistentField, targetEntity, context ) : local; } @@ -233,10 +233,12 @@ public class PersistentAttributesHelper { private static String getMappedByFromTargetEntity( CtField persistentField, CtClass targetEntity, - EnhancementContext context) { + EnhancementContext context) throws NotFoundException { // get mappedBy value by searching in the fields of the target entity class for ( CtField f : targetEntity.getDeclaredFields() ) { - if ( context.isPersistentField( f ) && getMappedByFromAnnotation( f ).equals( persistentField.getName() ) ) { + if ( context.isPersistentField( f ) + && getMappedByFromAnnotation( f ).equals( persistentField.getName() ) + && isAssignable( persistentField.getDeclaringClass(), inferFieldTypeName( f ) ) ) { log.debugf( "mappedBy association for field [%s#%s] is [%s#%s]", persistentField.getDeclaringClass().getName(),