Creating a composite Unique constraints on multiple columns jpa

Sometimes We need to define two or more columns combination make a unique row in a table Then we can use the following code snapshot in Entity class for spring.
@Table(name = "accounts",uniqueConstraints =@UniqueConstraint(columnNames = {"account_number","bank_id"}))
public class Account{

@Column(name = "account_number")
private String accountNumber;

@Column(name = "bank_id")
private String bankId;
.....setter and getter
}

Reactions

Post a Comment

0 Comments