It is just like any custom constraint. I admit the concrete implementation is not in the docs, but it is really not hard:
Code:
@Target( { TYPE })
@Retention(RUNTIME)
@Constraint(validatedBy = PassengerCountValidator.class)
@Documented
public @interface PassengerCount {
String message() default "{foo}";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
}
and
Code:
public class PassengerCountValidator implements ConstraintValidator<PassengerCount, Car> {
public void initialize(PassengerCount constraintAnnotation) {
}
public boolean isValid(Car car, ConstraintValidatorContext constraintContext) {
if (car == null)
return true;
return car.getPassengers().size() < 5
}
}
That said, I also created a Jira issue for clearing up the documentation -
https://hibernate.onjira.com/browse/HV-604--Hardy