Hi everyone, I'm having a problem with eager fetching. I'm attempting to set up a Criteria query that has appropriate constraints and fully hydrates the objects I need to perform some business logic. For some reason one of the collections that I'm trying to specify should be fetched eagerly contines to be fetched lazily. I've just been playing with the Criteria API for a short time, so it's possible that I'm doing something dumb. Any advice would be appreciated.
Admission has a Set of Programs
Admission has a Child
I would think that the line below would force an eager fetch of the programs set, but it doesn't seem to. Is this because I've added a Criteria object that refers to the programs collection as well? If so, how do I specify the FetchMode after I make the createCriteria call?
crit.setFetchMode("programs", FetchMode.EAGER);
Hibernate version: 2.1.2
Mapping documents:
From Admission.hbm.xml:
<set name="programs" lazy="true" inverse="true" cascade="none">
<key>
<column name="admissionId" />
</key>
<one-to-many
class="org.abc.portal.Program"
/>
</set>
Code between sessionFactory.openSession() and session.close():
sess = SessionFactoryUtils.getSession(getSessionFactory(), true);
Criteria crit = sess.createCriteria(Admission.class);
crit.add(Expression.isNull("endDate")); //we want an open admission
crit.setFetchMode("programs", FetchMode.EAGER); //we're iterating over our programs later, so get them
crit.createCriteria("child")
.setFetchMode("childChqs", FetchMode.EAGER) //we're going to want all of the outcomes
.setFetchMode("bers2Tests", FetchMode.EAGER);
Criteria programCriteria = crit.createCriteria("programs");
programCriteria.add(Expression.isNull("endDate"));
programCriteria.createCriteria("clinician").add(Expression.eq("login", login)); //we want to match on the clinician's login
programCriteria.setFetchMode("programType", FetchMode.EAGER);
List currentAdmissions = crit.list();
|