-->
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.  [ 9 posts ] 
Author Message
 Post subject: how to fetch a graph without lazy loading - preload ?
PostPosted: Sat Oct 06, 2007 2:33 am 
Newbie

Joined: Tue May 08, 2007 11:25 am
Posts: 15
Hi List,


I would like to avoid lazy loading in my application depending on the context.
Here is my object graph :

A
AA
AAA AAB AAC

All relations are one-to-many (A contains may AA which contains many AAA AAB and AAC)

A child collections are mapped "lazy", because in most cases this is the intended behavior.
However in one case I would like to fetch all AAA - AAB and AAC objects without lazy loading.

Is there a way to do this with HQL ?

I've tried this by writing a query loading all AAA's and then left join fetch to its parents (AA - A), and then load all AAB's, which works correctly. But when I start looping the AA.AAB collection I see that the queries to fetch the AAB's are executed again although the objects are already in my session.

Any ideas ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 08, 2007 3:00 pm 
Newbie

Joined: Mon Sep 25, 2006 11:02 pm
Posts: 10
Use the fetch keword. It doesn't have to be a left join as it is in my example.

from A
left join fetch a.aa

When using Criteria use Criteria.SetFetchMode(FetchMode.Eager)

-Cole


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 08, 2007 3:19 pm 
Newbie

Joined: Tue May 08, 2007 11:25 am
Posts: 15
This does not work.
It only works for ONE collection.
I could use it to get AA.AAA but not to get AA.BBB and AA.CCC


Thanks for the proposal.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 08, 2007 3:52 pm 
Newbie

Joined: Mon Sep 25, 2006 11:02 pm
Posts: 10
Yes, that is the same problem I just posted when I saw yours. You cannot preload two associations because it would create a cartesian product (if using left outer joins). This is explicitly prohibited by NHibernate.

What might possibly work is setting the mapping to fetch="select". I might try that and see.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 09, 2007 12:30 am 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
A two-fer! http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/performance.html#performance-multi-query, near the bottom.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 09, 2007 3:06 pm 
Newbie

Joined: Mon Sep 25, 2006 11:02 pm
Posts: 10
Version 1.20 GA does not have UniqueResult. Also, what if I want to load a list of items that has two collections loaded? Could i use List?...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 10, 2007 4:56 pm 
Newbie

Joined: Tue May 08, 2007 11:25 am
Posts: 15
Thanks a lot.
I had no time to try out this solution jet, but I will certainly due so in the comming days !

I'll keep you posted if it works out well, looks good !


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 18, 2007 2:23 am 
Newbie

Joined: Tue May 08, 2007 11:25 am
Posts: 15
SEEMS TO WORK !

Instead of 80 seconds (by use of lazy loading) I get the data in 12 seconds !
And indeed the UniqueResult is not available but it works with the list as well.

Thanks for the proposal !!!!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 18, 2007 5:18 am 
Newbie

Joined: Sun Sep 10, 2006 12:27 pm
Posts: 13
gITs wrote:
SEEMS TO WORK !

Instead of 80 seconds (by use of lazy loading) I get the data in 12 seconds !
And indeed the UniqueResult is not available but it works with the list as well.

Thanks for the proposal !!!!


Hi, I have your same problem, what does it mean: "the UniqueResult is not available but it works with the list ".

Thank in advance
Giorgio


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