我哈瓦一个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
表中的外键,对吗?
它仍然不能取代'{别名}'。 –