Hibernate criteria query on different properties of different objects

后端 未结 3 779
谎友^
谎友^ 2021-02-01 07:41

Suppose I have classes like:

class A {
 B getB();
 C getC();
}

class B {
 String getFoo();
}

class C {
 int getBar();
}

and I want to filter

3条回答
  •  一个人的身影
    2021-02-01 08:15

    You only need to create one criteria object like so.

    Criteria criteria = session.createCriteria(A.class);
    criteria.add(Restriction.disjunction()
        .add(Restriction.eq("b.foo", "something"))
        .add(Restriction.eq("c.bar", 0)));
    

提交回复
热议问题