Creating a composite Unique constraints on multiple columns
When table is created before, it is necessary to remove it. Unique key is not added to existing table.
Use @UniqueConstraint
:
@Table(
uniqueConstraints=
@UniqueConstraint(columnNames={"author_id", "number"})
)
@Entity
class Book extends Model {
@ManyToOne
@JoinColumn(name = "author_id")
User author;
int number;
}