如何在唯一约束中包含引用的表列?我想为列toEmail
,receipt.receiptSeries
和receipt.receiptNum
的表调查创建唯一约束。
请参阅以下实体:
收据
@Entity
@Table(name = "RECEIPT")
public class Receipt {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
private Long id;
@Column(name = "RECEIPT_SERIES")
private String receiptSeries;
@Column(name = "RECEIPT_NUM")
private String receiptNum;
}
调查
@Entity
@Table(name = "SURVEY"}
public class Survey {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
private Long id;
@ManyToOne(optional = false)
@JoinColumn(name = "RECEIPT_ID")
private Receipt receipt;
@Column(name = "TO_EMAIL")
private String toEmail;
}
我尝试过使用以下方法但没有成功:
@Table(name = "SURVEY", uniqueConstraints = {
@UniqueConstraint(columnNames = {"TO_EMAIL", "RECEIPT.RECEIPT_SERIES", "RECEIPT.RECEIPT_NUM"})})
使用带有receiptSeries
和receiptNum
的复合主键作为收据不是一种选择。
答案 0 :(得分:0)
尝试类似的方法
@Table(name="notification_status", uniqueConstraints=
arrayOf(UniqueConstraint(columnNames= arrayOf("external_user_id",
"external_organization_id",
"notification_id"))))