简体   繁体   English

如何在实体类上为两个不同的不同列组合添加唯一约束

[英]How to add Unique Constraint on Entity class for Two different different combination of columns

要为2个diff diff列的组合添加唯一约束

There is no Hibernate annotation that checks uniqueness before insert/update. 没有Hibernate注释在插入/更新之前检查唯一性。 But there is annotation which will generate such a constraint to the database if automatic database creation is used: 但是,如果使用自动数据库创建,则有注释将对数据库产生这样的约束:

Try this one: When hibernate create a table in DB create unique constraint combination of these two columns. 尝试以下操作:休眠时在数据库中创建表时,请创建这两列的唯一约束组合。

@Table(
    name="Table_Name", 
    uniqueConstraints=
        @UniqueConstraint(columnNames={"Column1", "Column2"})
)

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

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