How to apply unique constraints using annotation

前端 未结 3 1674
别那么骄傲
别那么骄傲 2021-02-12 22:41
@Column(name = \"userId\")
    @UniqueConstraint
    private Integer userId;

I am using these annotation for entering data into database table. i want

3条回答
  •  执念已碎
    2021-02-12 22:49

    Here's an example of how to use @UniqueConstraint:

    @Entity
    @Table(name = "contact", 
      uniqueConstraints = @UniqueConstraint(columnNames = {"name", "company_id"}))
    public class Contact {
      ...
    }
    

    This specifies that the combination of the "name" column and the "company_id" column will be unique.

提交回复
热议问题