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: Cannot fetch multiple collections in a single query
PostPosted: Tue Apr 14, 2009 9:10 am 
Newbie

Joined: Sun Jul 06, 2008 8:55 am
Posts: 3
Hi,

I have a entity Recipe and it has 3 collections images, comments and ingredients. The are mapped as a bag.

For a website I want to load the recipe collections with the recipe ie not lazy load so I discovered I could do that using this query

from Recipe r
left join fetch r.Images
left join fetch r.Ingredients
left join fetch r.Comments

But this gives an exception

Cannot fetch multiple collections in a single query if one of them is a bag

So how do I not lazy load my recipe and have the collections loaded allowing for the fact that there may not be any rows in that collection?

I'm new at this and need an explanation

Malcolm


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 14, 2009 9:39 am 
Regular
Regular

Joined: Thu Sep 06, 2007 2:22 am
Posts: 108
Location: Noida,India
Hi malcolms,
This is a limitation that you can't parallel load multiple collection eagerly using join if any one of collection is mapped using bag.

One solution which you can try is add following new attributes (lazy and fetch) in one-to-many element for Ingredients and Comments property -

Code:
<one-to-many name="Ingredients" lazy="false" fetch="select" />
<one-to-many name="Comments " lazy="false" fetch="select" />



and then try following query-


Code:
from Recipe r
left join fetch r.Images



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.