@UniqueConstraint annotation in Java

后端 未结 8 1554
囚心锁ツ
囚心锁ツ 2020-12-02 05:20

I have a Java bean. Now, I want to be sure that the field should be unique.

I am using the following code:

@UniqueConstraint(columnNames={\"username\         


        
8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-02 06:01

       @Entity @Table(name = "stock", catalog = "mkyongdb",
       uniqueConstraints = @UniqueConstraint(columnNames =
       "STOCK_NAME"),@UniqueConstraint(columnNames = "STOCK_CODE") }) public
       class Stock implements java.io.Serializable {
    
       }
    

    Unique constraints used only for creating composite key ,which will be unique.It will represent the table as primary key combined as unique.

提交回复
热议问题