tags:

views:

59

answers:

1

i have a java bean , now i want to be sure that the field sholud be unique. Am using following code

@UniqueConstraint(columnNames={"username"})
    public String username;

But am geting some error.

@UniqueConstraint is dissallowed for this location

Whats the proper way to use unique constraint?

Note:I am using play framework

+2  A: 

To ensure a field value is unique you can write

@Column(unique=true)
String username;

The @UniqueConstraint annotation is for annotating multiple unique keys at the table level, which is why you get an error when applying it to a field.

References (JPA TopLink):

mdma