-->
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.  [ 3 posts ] 
Author Message
 Post subject: Loading more than one one-to-many association?
PostPosted: Fri Jan 28, 2005 8:42 pm 
Beginner
Beginner

Joined: Sat Sep 25, 2004 12:42 am
Posts: 27
I’m trying to figure out the best method of loading more than one association. I’ve been looking through Hibernate in Action, the reference and this forum and everything seems to be focused on one association at a time.

To keep things clear I’ll use the auction system example found in Hibernate in Action. Now, say the Item class had two one-to-many associations, the first association being Bids (as per the book) and the second being Comments.

I know I want to load both of these associations so I try:
Code:
from Item as item
left join fetch item.bids
left join fetch item.comments

This executes fine but when I try and access the comments collection I get “LazyInitializationException: Failed to lazily initialize a collection”. OK, so I expected this because hibernate limits you to fetching one collection eagerly.

The best method I could find in the documentation was lazy loading with the batch-size option (reducing the number of calls). But then I’m required to iterate over the list of returned Items ensuring that the Bids and Comments are initialised.

So, my question is, is there a better/easier way?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 28, 2005 8:45 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This is the best way "for now". We want to remove the mentioned limitation soon.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 28, 2005 9:04 pm 
Beginner
Beginner

Joined: Sat Sep 25, 2004 12:42 am
Posts: 27
Cheers Gavin.

p.s. Thanks for doing the presentation at Sensis a while back.


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