-->
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.  [ 4 posts ] 
Author Message
 Post subject: Lazy loads in separate sessions.
PostPosted: Thu Sep 04, 2003 1:41 pm 
Not sure if I can do this or not, but what we essentially want to have at my business is a shared Struts tile that renders result sets in a number of different views (ie, an embedable view). Seems easy enough. Each row of the result is a Hibernate "Business" object and each "Business" object has a one-to-many mapping with a "BusinessLocation" object, defined as a lazy loading Hibernate set. The result set implements pagination using the jsptags.com paging library.

When a user initially submits their search criteria, I load up a list of Business objects from the database using Hibernate (say 150 of them) that match the criteria. Each page of the result set only has 30 records. Now, when each page is rendered, I need access to the locations -- were I to load up all locations for all 150 businesses (approx 3 each or ~450 records) the initial retrieval would take about 3x-4x as long. When implemented, however, I end up getting a LazyInitializationException when changing pages.

To my a long question short: is it possible to lazily load a collection on an object outside of the session that the object was originally loaded in *but* inside a second session?


Top
  
 
 Post subject:
PostPosted: Thu Sep 04, 2003 10:08 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Well, you can do it using session.lock(). But this is absolutely the wrong way to do it. If you use a query with a FETCH of the objects you need, they will already be initialized when you get to the view.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 05, 2003 11:25 am 
gavin wrote:
Well, you can do it using session.lock(). But this is absolutely the wrong way to do it. If you use a query with a FETCH of the objects you need, they will already be initialized when you get to the view.


what if the total amount of information in the result set is so large that you cannot realistically pull it all back at once? ie, a result set of 2000 records, paging at 20 records a pop and each record has 3 collections each that need to be loaded for display. the sheer amount of data that needs to come back can overwhelm the initial query execution -- whether you use FETCH or Hibernate.initialize().

as for session.lock(), i did see this in the hibernate 2.1b2 roadmap:

support for passing a transient object to Session.lock() (DONE)
(*) to allow initialization of associations, eg.
if ( !Hibernate.isInitialized( foo.getBars()) ) session.lock(foo, LockMode.NONE);
Iterator iter = foo.getBars().iterator();

based on what you said, however, doing this is absolutely the wrong way to do it. if that is the case, was this functionality in 2.1b2 put here for some other reason?

thanks!
james


Top
  
 
 Post subject:
PostPosted: Fri Sep 05, 2003 11:36 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
It was added for the purpose of usecases like:


* execute big query
* display results to user
* user selects a row of results
* go back and fetch collections owned by that row, after locking the object in a new session


and similar stuff.

Quote:
what if the total amount of information in the result set is so large that you cannot realistically pull it all back at once?



Dude, if you are pulling a result set that is too huge for JDBC, it is also to huge to display to the user on one page!


Perhaps your usecase is actually similar to the one i describe above.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.