if (key == null) {
mappedValue = toMongoObject(value, false);
} else {
mappedValue = keyToRef(key);
if (mappedValue == value) {
throw new ValidationException("cannot map to @Reference/Key<T>/DBRef field: " + value);
}
}
}
} catch (Exception e) {
LOG.error("Error converting value(" + value + ") to reference.", e);