|
Actually looking at that code some more, I think maybe the determination of where to look for the field is just too simplistic. I wonder if instead for any and all cases we should not look for getDeclaredField first and fall back to getField.
ATM this code does:
final Field field = attribute.getPersistentAttributeType() == Attribute.PersistentAttributeType.EMBEDDED
? metamodelClass.getField( name )
: metamodelClass.getDeclaredField( name );
What I wonder is whether it is ok to do this instead:
Field field;
try {
field = metamodelClass.getDeclaredField( name );
}
catch ( NoSuchFieldException e ) {
try {
field = metamodelClass.getField( name );
}
catch ( NoSuchFieldException e ) {
LOG.unableToLocateStaticMetamodelField( metamodelClass.getName(), name );
}
}
...
The other thing I find curious here is the attribute.getPersistentAttributeType() == Attribute.PersistentAttributeType.EMBEDDED check. If this affects composites, shouldn't this also be applied to fields of the composite rather than just fields that are a composite?
final boolean allowNonDeclaredFieldReference =
attribute.getPersistentAttributeType() == Attribute.PersistentAttributeType.EMBEDDED
|| attribute.getDeclaringType().getPersistenceType() == PersistenceType.EMBEDDABLE;
final Field field = allowNonDeclaredFieldReference
? metamodelClass.getField( name )
: metamodelClass.getDeclaredField( name );
|