-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate2 FetchMode.EAGER not working
PostPosted: Wed Sep 27, 2006 7:37 pm 
Newbie

Joined: Fri Feb 24, 2006 4:50 pm
Posts: 2
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();


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.