我哈瓦一個BaseEntity
限定了@Id String id
。我想在與匹配的@ManyToOne
關係上使用休眠過濾器。我還有一層層次結構,我不知道它是否有所作爲,所以我會將其納入以防萬一。休眠過濾條件:訪問嵌套屬性/用途別名
@Entity
public class Market extends BaseEntity {}
@MappedSuperclass
@FilterDef(name = "market", parameters = @ParamDef(name = "marketId", type = "string"))
@Filter(name = "market", condition = "{alias}.market.id = :marketId")
public abstract class MarketSpecificEntity extends BaseEntity {
@ManyToOne
private Market market;
}
@Entity
public class Product extends MarketSpecificEntity {}
據我所知,{alias}
應該替換爲hibernate使用的別名。從ProductRepository.findAll()
SQL:
select product0_.id as id1_1_, product0_.market_id as market_i2_1_ from product product0_ where {alias}.market.id = ?
Ommitting別名工作在非嵌套屬性,但在嵌套id
它不會(如預期):
select product0_.id as id1_1_, product0_.market_id as market_i2_1_ from product product0_ where market.id = ?
我使用aliases
參數也嘗試@Filter
建議in this answer但我不明白如何適應。
還要說明一點:比較不能導致JOIN
。這是因爲market.id
是保存在Product
表中的外鍵,對嗎?
它仍然不能取代'{別名}'。 –