I have three JPA entities: A, B and C. B and C inherit A with joined strategy. Is it possible to override a Bean Validation constraint in the subclasses? For example, I would like B to have a @NotNull constraint in one field and C to have a @Null constraint in the same field.
I was thinking to do it by using Bean Validation groups, however I don't know how to define that B must be validated with one group and C with another group.
Code to illustrate the problem:
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
...
public abstract class A {
...
@Column(name="FIELD")
private Integer field;
...
}
@Entity
public class B extends A {
...
//@NotNull in field
...
}
@Entity
public class C extends A {
...
//@Null in field
...
}