'How to add validation checks spanning multiple fields in a JPA entity

How to add validation checks spanning multiple fields in a JPA entity. If birthDate is present, then deathDate should be higher than birthDate. How do I enforce it

@Entity
@Table(name = "users")
public class User {

    private Date birthDate;

    private Date deathDate;

}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source