JPA - @Column (unique=true) - What is really point of having 'unique' attribute?

后端 未结 3 1998
别那么骄傲
别那么骄傲 2020-12-29 01:46

Suppose I am having \'subject\' table

CREATE TABLE subject (id int PRIMARY KEY, name VARCHAR(255) **UNIQUE**)

and associated Mapped Object,

3条回答
  •  清歌不尽
    2020-12-29 02:20

    unique in @Column is used only if you let your JPA provider create the database for you - it will create the unique constraint on the specified column. But if you already have the database, or you alter it once created, then unique doesn't have any effect.

提交回复
热议问题