1

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;

}
Rpj
  • 5,348
  • 16
  • 62
  • 122
  • where do you want to apply those checks ? – tknkrtl Feb 04 '22 at 07:48
  • It depends on what and how you want to validate but if you're using Hibernate the accepted answer of this question would probably be ideal to you: https://stackoverflow.com/questions/37878992/custom-jpa-validation-in-spring-boot – Nico Feb 04 '22 at 08:17
  • Is there a better way to achieve this, without relying on the underlying persistence provider – Rpj Feb 04 '22 at 08:53
  • Does this answer your question? [How can I validate two or more fields in combination?](https://stackoverflow.com/questions/2781771/how-can-i-validate-two-or-more-fields-in-combination) – Simon Martinelli Feb 04 '22 at 12:46

0 Answers0