I have four entities that are involved in a query that I'm having a little trouble with. The relationship is as follows : Exchange----*Contract*----*Combo----*Trade
and the (simplified) entities are as follows:
@Entity
public class Exchange implements Serializable {
@Id(name="EXCHANGE_ID")
private long exchangeId;
@Column
private String exchangeShortName;
}
@Entity
public class Contract implements Serializable {
@Id
private long contractId;
@Column
private String contractName;
@ManyToOne
@JoinColumn(name="EXCHANGE_ID")
private Exchange exchange;
@ManyToMany
@JoinTable(name="CONTRACT_COMBO",
joinColumns = { @JoinColumn(name="CONTRACT_ID") },
inverseJoinColumns = {@JoinColumn(name="COMBO_ID")})
private Set<Combo> combos;
@Column(name = "ACTIVE_FLAG")
private String activeFlag;
}
@Entity
public class Combo implements Serializable {
@Id
@Column(name="COMBO_ID")
private Integer id;
@ManyToMany
@JoinTable(name="CONTRACT_COMBO",
joinColumns = { @JoinColumn(name="COMBO_ID") },
inverseJoinColumns = {@JoinColumn(name="CONTRACT_ID")})
private Set<Contract> legs;
@OneToMany(mappedBy = "combo")
private Set<Trade> trades;
}
@Entity
public class Trade implements Serializable {
@Id
@Column(name="TRADE_ID")
private long tradeId;
@Column(name="REFERENCE")
private String reference;
@ManyToOne
@JoinColumn(name="COMBO_ID")
private Combo combo;
}
I want to get a list of all trades for a particular exchange which I can't quite get to work with MEMBER OF
. Any help would be appreciated.
Try this
select distinct t
from Trade t
join t.combo c
join c.legs l
join l.exchange e
where e.exchangeShortName = 'whatever'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With