if (value == null) {
return true;
}
final String[] propertyNames = getPropertyNames(
((FieldContext) context).getField().getName());
final GenericModel model = (GenericModel) validatedObject;
final Model.Factory factory = Model.Manager.factoryFor(model.getClass());
final String keyProperty = factory.keyName();
final Object keyValue = factory.keyValue(model);
//In case of an update make sure that we won't read the current record from database.
final boolean isUpdate = (keyValue != null);
final String entityName = model.getClass().getName();
final StringBuffer jpql = new StringBuffer("SELECT COUNT(o) FROM ");
jpql.append(entityName).append(" AS o where ");
final Object[] values = new Object[isUpdate ? propertyNames.length + 1 :
propertyNames.length];
final Class clazz = validatedObject.getClass();