// locate field
try {
field = lookupFieldInHierarchy(beanClass, propertyName);
}
catch (SecurityException e) {
throw new CayenneRuntimeException("Error accessing field '"
+ propertyName
+ "' in class: "
+ beanClass.getName(), e);
}
catch (NoSuchFieldException e) {
throw new CayenneRuntimeException("No field '"
+ propertyName
+ "' is defined in class: "
+ beanClass.getName(), e);
}
// set accessability
if (!Util.isAccessible(field)) {
field.setAccessible(true);
}
if (propertyType != null) {
// check that the field is of expected class...
if (!field.getType().isAssignableFrom(propertyType)) {
// allow primitive to object conversions...
if (!PropertyUtils.normalizeType(field.getType()).isAssignableFrom(
PropertyUtils.normalizeType(propertyType))) {
throw new CayenneRuntimeException("Expected property type '"
+ propertyType.getName()
+ "', got '"
+ field.getType().getName()
+ "'. Property: '"
+ beanClass.getName()