我正在使用JPA 2.0 / Hibernate验证来验证我的模型。现在我有一个情况需要验证两个字段的组合:
public class MyModel {
public Integer getValue1() {
//...
}
public String getValue2() {
//...
}
}
如果 getValue1()
和 getValue2()
都为 null
,那么该模型就是 无效的,否则就是有效的。
我如何使用 JPA 2.0/Hibernate 进行此类验证?使用简单的 @NotNull
注释时,两个getter都必须为非空才能通过验证。