Hibernate criteria query on different properties of different objects

后端 未结 3 853
谎友^
谎友^ 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:09

    Use aliases instead of nested criteria:

    Criteria criteria = session.createCriteria(A.class)
     .createAlias("b", "b_alias")
     .createAlias("c", "c_alias")
     .add(Restrictions.disjunction()
      .add(Restrictions.eq("b_alias.foo", "Something"))
      .add(Restrictions.eq("c_alias.bar", "0"))
     );
    

提交回复
热议问题