How can I validate two or more fields in combination?
- by DR
I'm using JPA 2.0/Hibernate validation to validate my models. I now have a situation where the combination of two fields has to be validated:
public class MyModel {
public Integer getValue1() {
//...
}
public String getValue2() {
//...
}
}
The model is invalid if both getValue1() and getValue2() are null and valid otherwise.
How can I perform this kind of validation with JPA 2.0/Hibernate? With a simple @NotNull annotation both getters must be non-null to pass validation.