How can I validate two or more fields in combination?
Posted
by DR
on Stack Overflow
See other posts from Stack Overflow
or by DR
Published on 2010-05-06T14:21:36Z
Indexed on
2010/05/06
14:28 UTC
Read the original article
Hit count: 220
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.
© Stack Overflow or respective owner