java—从一方到另一方的许多关系都需要jpq

iih3973s  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(324)

我得买些模型,例如付款单和运单。一个付费侦察员身上可以有一套运单。但我不想把运单和它紧紧地联系在一起。所以我创建了如下模型:
付款侦察

@SuppressWarnings("serial")
@Entity
public class PaymentReconciliation extends BaseEntity {
@Column
private String parentId;
@Column
private BigDecimal grossAmount;
@Column
private String currency;
@Column
private Integer totalNumberOfPackages;
@Column
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "PayReconWaybillMap", joinColumns = { 
@JoinColumn(name = "reconId") }, inverseJoinColumns = {
        @JoinColumn(name = "waybillId") })
private Set<WayBill> waybill = new HashSet<WayBill>();
}

瓦比尔

@SuppressWarnings("serial")
 @Entity
 public class PaymentReconciliation extends BaseEntity {
 @Column(nullable = false, unique = true)
 private String barCode;
  @Column
  private String consigneeName;
  @Column
  @JsonIgnore
  private String countryCode;

 }

现在,我有三张table。所以在发展之后事情就结束了。我要拿不附在任何付款通知上的运单。谁能帮我弄到这个吗。

axzmvihb

axzmvihb1#

可以将“连接表”Map到新实体上 PayReconWaybillMap ,使用 @ManyToOnePaymentReconciliation 指中间实体:

@ManyToOne
private PayReconWaybillMap pwm;

而在 PayReconWaybillMap 实体:

@OneToMany
private List<PaymentReconciliation> pr;

@OneToMany
private List<WayBill> wb;

所以,可以使用join,如下所示:

SELECT wb FROM WayBill wb 
LEFT JOIN PayReconWaybillMap pwm ON pwm.waybillId = wb.waybillId 
WHERE pwm IS NULL

相关问题