-->
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: Explict load of lazy loaded object?
PostPosted: Sat Jun 20, 2009 1:16 pm 
Newbie

Joined: Thu Sep 18, 2008 1:24 pm
Posts: 1
First of all...I am using Spring Annotations that that handle the session (i.e. session per request model).

I found that if I have the following logic:

Code:
public List<Child> getObjects(...) {
Session s = sessionFactory.getCurrentSession();
Criteria c = s.createCriteria(PARENT.class);
List<PARENT> parents = c.list();

List<Child> children = new ArrayList<Child>();
for (Parent p: parents){
   children.add(p.getChild());
}
return children;

now..by the time anything interesting happens on children (it has left the session).hence all children end up being null..
so my question is, is there anyway (PROPER WAY) I can explictly force the loading of the children in this situation.

I know I can do (well at least it appears to be working for me..but it feels like a hack).
Code:
public List<Child> getObjects(...) {
Session s = sessionFactory.getCurrentSession();
Criteria c = s.createCriteria(PARENT.class);
List<PARENT> parents = c.list();

List<Child> children = new ArrayList<Child>();
for (Parent p: parents){
   [color=#FF0000]p.getChild().getName()[/color] // i.e. call some/any function on the Child..will force hibernate to load the child.
   children.add(p.getChild());
}
return children;


any tips? is there not a way to simply do s.load(p.getChild())...


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.