}
Metadata metadata = (Metadata) getMetadata();
EntityType type = metadata.getEntityType(entity.getClass());
AssociationEnd association = metadata
.getAssociation(type, propertyName);
if (association != null) {
EntityType propertyEntityType = association.getType();
try {
Class<?> propertyClass = ReflectUtils.getSimpleClass(entity,
propertyName);
if (propertyClass == null) {
propertyClass = TypeUtils.getJavaClass(propertyEntityType);
}
Iterator<?> iterator = createQuery(
getSubpath(entity, propertyName), propertyClass)
.iterator();
ReflectUtils.setProperty(entity, propertyName,
association.isToMany(), iterator, propertyClass);
} catch (Exception e) {
getLogger().log(
Level.WARNING,
"Can't set the property " + propertyName + " of "
+ entity.getClass() + " for the service"