@UniqueConstraint and @Column(unique = true) in hibernate annotation

前端 未结 4 1837
别跟我提以往
别跟我提以往 2020-12-07 10:04

What is difference between @UniqueConstraint and @Column(unique = true)?

For example:

@Table(
   name = \"product_s         


        
4条回答
  •  一个人的身影
    2020-12-07 10:57

    In addition to Boaz's answer ....

    @UniqueConstraint allows you to name the constraint, while @Column(unique = true) generates a random name (e.g. UK_3u5h7y36qqa13y3mauc5xxayq).

    Sometimes it can be helpful to know what table a constraint is associated with. E.g.:

    @Table(
       name = "product_serial_group_mask", 
       uniqueConstraints = {
          @UniqueConstraint(
              columnNames = {"mask", "group"},
              name="uk_product_serial_group_mask"
          )
       }
    )
    

提交回复
热议问题