1
我有兩個外鍵,我也想爲約束 使用一個實體存在的JPA任何方式來定義的約束只會是唯一的,如果 相同FROM_CURRENCY_ID和TO_CURRENCY_ID重複,但允許值是否爲 反轉FROM_CURRENCY_ID和TO_CURRENCY_ID唯一約束複合主鍵在JPA
@Entity
@Table(name="CURRENCY_CONVERSION")
public class CurrencyConversion extends BaseEntity {
private static final long serialVersionUID = -2440725717151990999L;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "FROM_CURRENCY_ID")
private Currency fromCurrencyId;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "TO_CURRENCY_ID")
private Currency toCurrencyId;
@Column(name = "CURRENCY_RATE", nullable = false)
private Double rate;
// getter setters
}