JPA - @Column (unique=true) - What is really point of having 'unique' attribute?
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.
unique=true
in @Column
annotation will be used only in DDL generation
, it doesn't have any impact during runtime. The actual uniqueness checks happens in the database
.