Hi,
there is an error in the definition of the constructors of ConstraintViolationException in validation-api-1.0.CR3.jar.
They are defined
Code:
public <T> ConstraintViolationException(String message, Set<ConstraintViolation<?>> constraintViolations) { ... }
public <T> ConstraintViolationException(Set<ConstraintViolation<?>> constraintViolations) { ... }
but should be
Code:
public <T> ConstraintViolationException(String message, Set<ConstraintViolation<T>> constraintViolations) { ... }
public <T> ConstraintViolationException(Set<ConstraintViolation<T>> constraintViolations) { ... }
Otherwise you have to create an intermediate collection to use them (casts are not allowed here). E.g:
Code:
Set<ConstraintViolation<MyBean>> violations = validator.validateValue(MyBean.class, "field", value);
if (!violations.isEmpty()) {
throw new ConstraintViolationException(new HashSet<ConstraintViolation<?>>(violations));
}
I would have open an JIRA issue, but I'm not sure where (
http://opensource.atlassian.com/projects/hibernate/browse/BVAL?)