log.warning("Expected instance of " + Key.class + ". Found " + entity.getProperty(fieldName).getClass() + ". Skipping field.");
} else {
final long id = ((Key) entity.getProperty(fieldName)).getId();
if (id > 0) {
/**
* retrieve the referenced entity and copy its dto representation as an additional field into the originating dto object.
*/
final Dto relatedEntity = get(relatedEntityName, id, 1 + resolvDepth);
if (null == relatedEntity) {
log.warning(dto.getModule() + "/" + dto.getId() + " references a no-longer existing entity " + relatedEntityName + "/" + id);
dto.set(fieldName, 0);
// TODO should we persist this change of the Dto object?
} else {
dto.set(fieldName, relatedEntity.getId());
dto.set(fieldName + "_resolved", relatedEntity);
}
}
}
}