我想知道是否有办法使用硬编码值进行过滤器注释。我正在加入名为itemRate和ratemaster的两个表。 Rate master具有应用rateid和ratekind id的复合键。 rate kind id可以是3个id中的1个(主要,组件,项目费率)。
我的项目费率表知道应用程序并引用两个不同的列item_rate和rate(这是主要费率),
我的问题是,hibernate是否有办法对过滤器进行硬编码,因此当我调用getRate()
时,它会过滤速率种类ID为0的所有费率,当我调用getItemRate()
时将使用ratekind id为2来过滤所有费率吗?
我尝试做类似这样的事情来获得费率类型为0的费率主数据:
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumns({
@JoinColumn(name = "CIITM_RATE", nullable = false , updatable = false, insertable = false, referencedColumnName = "RATE"),
@JoinColumn(name = "CIITM_APPLICATION", nullable = false , updatable = false, insertable = false, referencedColumnName = "APPLICATION") })
@FilterJoinTable(name = "kindId", condition="RATEKINDID = 0")
public Ciratemaster getRateMaster() {
return rateMaster;
}
这是为了获得速率种类为2的费率主人:
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumns({
@JoinColumn(name = "CIITM_ITEM_RATE", nullable = false , updatable = false, insertable = false, referencedColumnName = "RATE"),
@JoinColumn(name = "CIITM_APPLICATION", nullable = false , updatable = false, insertable = false, referencedColumnName = "APPLICATION") })
@FilterJoinTable(name = "kindId", condition="RATEKINDID = 2")
public Ciratemaster getItemRateMaster() {
return itemRateMaster;
}
我尝试搜索hibernate网站和其他网站,但没有真正有效。我总是想出它不应该
时获取超过1个结果的错误提前致谢。
答案 0 :(得分:1)
尝试使用此代替过滤器:
@org.hibernate.annotations.Where(clause = "RATEKINDID = 2")
编辑:尝试JoinColumnsOrFormula注释:
@JoinColumnsOrFormulas({
@JoinColumnOrFormula(formula = @JoinFormula(value = "2", referencedColumnName = "RATEKINDID")),
@JoinColumnOrFormula(column = @JoinColumn(name = "CIITM_RATE", nullable = false , updatable = false, insertable = false, referencedColumnName = "RATE")),
@JoinColumnOrFormula(column = @JoinColumn(name = "CIITM_APPLICATION", nullable = false , updatable = false, insertable = false, referencedColumnName = "APPLICATION"))
})