JPA:需要多对多查询帮助
我有四个实体参与查询,但我遇到了一些问题。关系如下:Exchange----*Contract*----*Combo----*Trade
和(简化的)实体如下:
@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;
}
我想获取以下列表特定交易所的所有交易,我无法完全与 MEMBER OF
合作。任何帮助将不胜感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个
Try this
没有真正优化,但我认为这应该可以解决问题:
Not really optimized, but I think this should do the trick: