I have three entities like:
Code:
class A {
List<B> blist;
}
class B {
List<C> clist;
}
class C {
int size;
}
So I have one to many relations between:
- A and B
- B and C
I want to select all pairs (A,B) having C.size = 5.
I want to do that using criteria API.
I did :
Code:
hc = session.createCriteria(A.class, "a");
hc.createCriteria("a.blist", "b");
hc.createCriteria("b.clist", "c");
hc.add(Restrictions.eq("c.size", 5);
hc.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
Even if i include c only for restricting the query, the system gives pairs
<A,B,C> but i want to get only distinct pairs <A,B>
Is there a way to exclude C from "select " ?
Right now I'm using DetachedCriteria:
- Subselect.exists
- in
but both seems ineficient in terms of performance and the code is not readable.
Any other options?