HHH-10583 - [enhancer] also consider attribute type when finding the right mappedBy value
(cherry picked from commit c33735108a
)
This commit is contained in:
parent
7ef6400d05
commit
2ae61a3e33
|
@ -207,7 +207,7 @@ public class PersistentAttributesHelper {
|
||||||
PersistentAttributesHelper.hasAnnotation( persistentField, ManyToMany.class );
|
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 );
|
final String local = getMappedByFromAnnotation( persistentField );
|
||||||
return local.isEmpty() ? getMappedByFromTargetEntity( persistentField, targetEntity, context ) : local;
|
return local.isEmpty() ? getMappedByFromTargetEntity( persistentField, targetEntity, context ) : local;
|
||||||
}
|
}
|
||||||
|
@ -233,10 +233,12 @@ public class PersistentAttributesHelper {
|
||||||
private static String getMappedByFromTargetEntity(
|
private static String getMappedByFromTargetEntity(
|
||||||
CtField persistentField,
|
CtField persistentField,
|
||||||
CtClass targetEntity,
|
CtClass targetEntity,
|
||||||
EnhancementContext context) {
|
EnhancementContext context) throws NotFoundException {
|
||||||
// get mappedBy value by searching in the fields of the target entity class
|
// get mappedBy value by searching in the fields of the target entity class
|
||||||
for ( CtField f : targetEntity.getDeclaredFields() ) {
|
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(
|
log.debugf(
|
||||||
"mappedBy association for field [%s#%s] is [%s#%s]",
|
"mappedBy association for field [%s#%s] is [%s#%s]",
|
||||||
persistentField.getDeclaringClass().getName(),
|
persistentField.getDeclaringClass().getName(),
|
||||||
|
|
Loading…
Reference in New Issue