I have a Java bean. Now, I want to be sure that the field should be unique.
I am using the following code:
@UniqueConstraint(columnNames={\"username\
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):