简体   繁体   English

父母的休眠条件过滤器

[英]Hibernate Criteria filter by parent

I want to filter objects based in some conditions or if their parent is of a specific type. 我想根据某些条件或对象的父对象是特定类型来过滤对象。

class A {}

class B extends A {}

class O {
    A a;
    long n;
}

I want all O objects where n > 100 or a is of type B . 我想要所有n > 100a is of type B O对象。

In Criteria what would be the or condition Criteria会是什么or条件

Restrictions.eq("a.class", B.class)

I've had bugs though when a single-table inheritance type was chosen (using a discriminator), and where I had to use 但是,当选择单表继承类型(使用区分符)时,以及必须在哪里使用时,我都遇到了错误。

Restrictions.eq("a.class", B.DISCRIMINATOR_VALUE)

Note that class is an implicit property. 请注意, class是隐式属性。 You don't need to define anything special in the entity to make it work. 您无需在实体中定义任何特殊内容即可使其工作。

You can use "Restrictions" type to create a criteria... 您可以使用“限制”类型来创建条件...

From my experience, 根据我的经验,

it should be something like below 它应该像下面这样

Restrictions.ge("n", ) Restrictions.ge(“ n”,)

Sorry....don't remember the exact function name under Restrictions...You can check from the javadoc. 抱歉...。不记得“限制”下的确切函数名称了。可以从javadoc中进行检查。

And for the object comparison, it's the same way except that you can use "eq" and give the object as a restriction... 对于对象比较,除了可以使用“ eq”并将对象作为限制之外,其他方法相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM