HHH-10583 - [enhancer] also consider attribute type when finding the right mappedBy value

(cherry picked from commit c33735108a)
This commit is contained in:
barreiro 2016-03-22 06:20:54 +00:00 committed by Gail Badner
parent 7ef6400d05
commit 2ae61a3e33
1 changed files with 5 additions and 3 deletions

View File

@ -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(),