In JPA2, you can add the Unique constraint directly to the field:
@Entity
@Table(name="PERSON_TABLE")
public class Person{
@Id
@Column(name = "UUID")
private String id;
@Column(name = "SOCIALSECURITY", unique=true)
private String socialSecurityNumber;
@Column(name = "LOGINID", unique=true)
private String loginId;
}
IMHO its much better to assign the unique constraint directly to the attributes than at the beggining of the table.
If you need to declare a composite unique key however, then declaring it in the @table
annotation is your only option.
C
in@Column
and notc
!!! – KNU