我有一个连接表,看起来像这样。
EXCHANGE_RATE
------------------------------
ID BIGINT PK
SOURCE_CURRENCY_ID BIGINT FK
TARGET_CURRENCY_ID BIGINT FK
映射的 ExchangeRate.java
public class ExchangeRate {
protected ExchangeRage() {
this(null, null);
}
// for SELECT NEW
public ExchangeRate(Currency sourceCurrency, Currency targetCurrency) {
this.sourceCurrency = sourceCurrency;
this.targetCurrency = targetCurrency;
}
@Id private Long id;
@ManyToOne private Currency sourceCurrency;
@ManyToOne private Currency targetCurrency;
}
如何列出所有现有和不存在ExchangeRate
的给定sourceCurrency
?
例如,
- 共有三种货币。A、B 和 C。
- 已经有一个从 A 到 B 的 ExhangeRate
用下面的方法,如果sourceCurrency
是A
,
public List<ExchangeRate> listExchangeable(Currency sourceCurrency) {
//
}
如何获得以下列表?
ExchangeRate {
id: 0
sourceCurrency: A
targetCurrency: B
},
ExchangeRate {
id: NULL
sourceCurrency: A
targetCurrency: C
}