Hibernate Criteria filter by parent
I want to filter objects based in some conditions or if their parent is of a specific t开发者_JAVA百科ype.
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
.
In Criteria
what would be the or
condition
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. 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", )
Sorry....don't remember the exact function name under Restrictions...You can check from the javadoc.
And for the object comparison, it's the same way except that you can use "eq" and give the object as a restriction...
精彩评论