I work with MySQL/OPENJPA. I have a task to impose uniqueness in one of the table columns. From what I see I can do this in 2 ways.
Alter Table <table name> ADD UNIQUE <column name>
OR
@Table(name="<table name>", uniqueConstraints=@Unique(columnNames="<column name>"))
Which way is correct? Or maybe using both at the same time?
JPA annotation will be only used during generation of new db schema (so only if your persistence.xml has ddl-generation create-tables or drop-and-create). It doesn't effect existing tables nor it is checked by JPA.
So if your DB already exists you need to use ALTER TABLE