I have an object tree with 3 levels of nested one-to-many relationships:
A has-a Set<B>, B has-a Set<C> and C has-a Set<D>
All the set mappings are like this one in A.hbm.xml:
Code:
<set name="set_of_b" cascade="all">
<key column="A_ID" not-null="true"/>
<one-to-many class="B"/>
</set>
I want to write a query that returns an instance of A (id is provided) with all the nested sets fully populated (as if fetching is eager).
If I use fetch="join" in the set mappings, then it works out, but that would not be allowed.
I've tried the following query, but it's not working:
Code:
A a = (A) s.createCriteria(A.class)
.add(Restrictions.idEq(a_id))
.setFetchMode("set_of_b", FetchMode.JOIN)
.createCriteria("set_of_b")
.setFetchMode("set_of_c", FetchMode.JOIN)
.createCriteria("set_of_d")
.setFetchMode("set_of_d", FetchMode.JOIN)
.uniqueResult();
Please help.