Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPA unique constraint validation

How to validate Multiple column unique constraint in JPA entity. Is there any Hibernate validator for this purpose. I have added @UniqueConstraint annotation. But it is not doing any validation.And I also want to customize the error message.

like image 984
Biju CD Avatar asked Nov 02 '25 17:11

Biju CD


1 Answers

The @UniqueConstraint is not related to hibernate-validator. It cannot be handled by java-only validation, it needs a trip to the database.

It tells hibernate that the database has a unique constraint. If the database does not have a unique constraint, I think the insert should pass.

like image 156
Bozho Avatar answered Nov 04 '25 08:11

Bozho