lundi 2 mars 2015

How to put a unique database constrain correctly – using Alter Table or in JPA annotation?



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.



  1. Use Alter Table ADD UNIQUE


OR



  1. Using JPA annotation: @Table(name="", uniqueConstraints=@Unique(columnNames=""))


Which way is correct? Or maybe using both at the same time?




Aucun commentaire:

Enregistrer un commentaire