简体   繁体   English

JPA唯一约束验证

[英]JPA unique constraint validation

How to validate Multiple column unique constraint in JPA entity. 如何在JPA实体中验证多列唯一约束。 Is there any Hibernate validator for this purpose. 是否有用于此目的的Hibernate验证器。 I have added @UniqueConstraint annotation. 我添加了@UniqueConstraint注释。 But it is not doing any validation.And I also want to customize the error message. 但它没有进行任何验证。我还想自定义错误消息。

The @UniqueConstraint is not related to hibernate-validator. @UniqueConstraint与hibernate-validator无关。 It cannot be handled by java-only validation, it needs a trip to the database. 它不能通过仅Java验证来处理,它需要访问数据库。

It tells hibernate that the database has a unique constraint. 它告诉hibernate数据库有一个唯一的约束。 If the database does not have a unique constraint, I think the insert should pass. 如果数据库没有唯一约束,我认为插入应该通过。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM