-->
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.  [ 2 posts ] 
Author Message
 Post subject: Is an open session required for lazy initialization?
PostPosted: Wed Feb 18, 2004 6:37 pm 
Regular
Regular

Joined: Wed Sep 03, 2003 9:56 pm
Posts: 58
I have a mildly deep object graph (5 levels), comprised of aproximately 200 objects total. I have a tree control for browsing this heirarchy. When I launch my tree viewer, I only want to see the root nodes. With SQL tracing on, I see that I'm getting the entire object graphs loaded as a result of my session.find().

I have proxies set throughout, and my collections declare lazy="true".

The method that does the lookup looks like this (error processing removed):
Code:
public List findRootNodes() {
  s = SessionManager.getSessionFactory().openSession();
  results = s.find("from RootNode");
  s.close();
  return results
}


Is there something else I need to do to get the objects to load only when I access them (i.e. keep the session open during user browsing)?

Thanks.

FWIW, this is a thick-client application talking directly to the database.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2004 6:42 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Pick one:

- You have to keep the Session open (several strategies)
- You initialize all required lazy collections and proxies manually before you close the Session
- You can eagerly fetch all required data with an HQL query before closing
- You can reattach (by calling lock() or update, see the API documentation) an object to a new (second) Session when a view is rendered

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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

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.