@UniqueConstraint this annotation is used for annotating single or multiple unique keys at the table level separated by comma, which is why you get an error. it will only work if you let JPA create your tables
Example
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@Builder(builderClassName = "Builder", toBuilder = true)
@Entity
@Table(name = "users", uniqueConstraints = @UniqueConstraint(columnNames = {"person_id", "company_id"}))
public class AppUser extends BaseEntity {
@Column(name = "person_id")
private Long personId;
@ManyToOne
@JoinColumn(name = "company_id")
private Company company;
}
https://docs.jboss.org/hibernate/jpa/2.1/api/javax/persistence/UniqueConstraint.html
On the other hand To ensure a field value is unique you can write
@Column(unique=true)
String username;