class UniquePropertyValidator implements ConstraintValidator<UniqueProperty, WithId<?>> {

    @Override
    public boolean isValid(final WithId<?> value, final ConstraintValidatorContext context) {
        if (value == null) {
            return true;
        }

        final PropertyAccessor bean = new BeanWrapperImpl(value);

        final String propertyValue = String.valueOf(bean.getPropertyValue(property));

        @SuppressWarnings({"rawtypes", "unchecked"})
        final Class<WithId> modelClass = (Class) value.getKind().modelClass;

        @SuppressWarnings("unchecked")
        final Set<String> ids = dataManager.fetchIdsByPropertyValue(modelClass, property, propertyValue);

        final boolean isUnique = ids.isEmpty() || value.getId().map(id -> ids.contains(id)).orElse(false);

        if (!isUnique) {
            context.disableDefaultConstraintViolation();
            context.unwrap(HibernateConstraintValidatorContext.class).addExpressionVariable("nonUnique", propertyValue)
                .buildConstraintViolationWithTemplate(context.getDefaultConstraintMessageTemplate())
                .addPropertyNode(property).addConstraintViolation();
        }

        return isUnique;
    }

}