| Nevermind the entities, JPA, and custom constraints. This issue can be seen using normal beans with built-in validators. Working on getting you a test case. You'll have to bare with me, as I have to set this up from scratch (including my solution) on a new system. This is an example of how we are calling the validator:
private TestBean testBeanBuiltIn;
private ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
private Validator validator = factory.getValidator();
private static final int MAX_ITERATIONS = 1000000;
...
Set<ConstraintViolation<TestBean>> constraintViolations = null;
for(int i = 0; i < MAX_ITERATIONS; i++)
{
constraintViolations = validateBean(testBeanBuiltIn);
}
...
private <T> Set<ConstraintViolation<T>> validateBean(
T bean) {
Set<ConstraintViolation<T>> constraintViolations = null;
constraintViolations = validator.validate(bean);
return constraintViolations;
}
That one is interesting, why do you use reflection in your class-level constraint? I'd expect you could access the entity state via normal field/getter accesses?
The code above shown in the code above, our we have a method that can take any bean class, and have over 500 different bean types that can be passed. I've attached an example bean using built-in validators. TestBean.java |