Even though I set the attribute to be @Column(unique=true)
, I still insert a duplicate entry.
@Entity
public class Customer {
@Id
@Ge
Try specifying the unique constraint at the class level using
@Table(uniqueConstraints={@UniqueConstraint(columnNames={"name"})})
public class Customer {
...
private String name;
}
@Column(unique=true) doesn't work for me but when I used @UniqueConstraint at the class level, the column in the database (MySql) was appropriately set as unique.
I hope this helps someone else who may face this same issue in the future
Make sure to delete the tables created by hibernate in your database. And then re-run your hibernate application again.