给出两个实体:
@Override
public String toString()
{
return voucher_period;
}
PurchaseProductGroup
,其PurchaseProduct
列可以是status
(有效)或'A'
(已删除)和'D'
中定义的多对多关系:
PurchaseProductGroup
如何对此进行限制,以便排除状态为/** The purchase products linked to this group. */
@ManyToMany
@JoinTable(name = "purchaseprodgrp_purchaseprod",
joinColumns = @JoinColumn(name = "ppg_id"),
inverseJoinColumns = @JoinColumn(name = "ppr_id"))
private List<PurchaseProduct> purchaseProducts;
的buyProducts?
尝试在'D'
注释的下方添加以下内容,但两列都失败并且列的“无效标识符”例外:
@ManyToMany
@Where(clause = "status <> 'D'")
还尝试在实体级别添加@WhereJoinTable(clause = "purchaseProduct.status <> 'D'")
,但这似乎不会影响关系集合的内容 - 由ConvLSTM2D备份。
答案 0 :(得分:2)
请尝试以下代码:
@ManyToMany
@JoinTable(name = "purchaseprodgrp_purchaseprod",
joinColumns = @JoinColumn(name = "ppg_id"),
inverseJoinColumns = @JoinColumn(name = "ppr_id"))
@Where(clause = "ppr_status <> 'D'")
private List<PurchaseProduct> purchaseProducts;
这可能类似于您之前尝试过的内容,但实现此功能的关键点是ppr_status
是实际的列名。因此PurchaseProduct
实体应具有以下内容:
@Column(name="ppr_status")
public String getStatus() {
return status;
}
如果您已将字段命名为ppr_status
,则可能不需要@Column
。但根据您的上述评论,我们需要告诉Hibernate如何映射此列。