I have a Inheritance with Single Table mapping in JPA, Say Class A and B extends some abstract entity, so I have to make columns from A & B nullable at DB end but if someone is trying to persist A then all fields of A should be not null and i want to enforce this by code.
Can I use following code to achieve this -
@Entity
@DiscriminatorValue("1")
public Class A extends SomeAbstractEntity{
@Basic(optional = false)
private String nameOfA;
}
I read this answer @Basic(optional = false) vs @Column(nullable = false) in JPA and thought this may be achievable but wanted to know what is the best way.