1

I was wondering if there is a way to have a filter annotation with a hard coded values. I am joining two tables called itemRate and ratemaster. Rate master has a composite key of application rateid and ratekind id. The rate kind id can be 1 of 3 id's (primary, component, item rate).

My Item Rate table knows the application and references two different columns item_rate and rate (which is the primary rate),

My question is, is there a way with hibernate to hard code a filter so when i call getRate() it will filter on all rates with a rate kind id of 0 and when i call getItemRate() it will filter on all rates with a ratekind id of 2?

I tried doing something like this to get the rate masters with a rate kind of 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;
}

and this to get rate masters with rate kinds of 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;
}

I tried searching hibernate website and other sites and nothing has really worked. I always come up with the error that it fetched more than 1 result when it shouldn't

Thanks in advance.

4

1 回答 1

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"))
})
于 2012-11-16T22:41:38.217 回答