-->
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.  [ 6 posts ] 
Author Message
 Post subject: Eagerly loading multiple collections
PostPosted: Thu Mar 10, 2005 9:51 am 
Newbie

Joined: Mon Mar 07, 2005 7:25 am
Posts: 10
Hi, I'm working on a POC for a very large project, but we're having issues with object detachment:

Suppose you have:
Code:
Object A
+collection(B) // lazy loaded
+collection(C) // lazy loaded

basically an object with more than one collection.

Now, using Criteria, try to get a list of A objects that are complete (both collections have been loaded) and detached. For one collection, this is easy to do with setFetchMode("Bs",FetchMode.JOIN). But, there seems to be no way to do this with the collection of Cs as well.

Setting FetchMode.JOIN twice is ignored because of Cartesian product issues. FetchMode.SELECT does a secondary select (to be expected), but this is not done eagerly, so you get a LazyLoadingException anyway.

I've really thouroughly researched this (forum, TFM, Wiki, google and several stabs at the Hibernate source code), but to no avail. Because all the lazy loading is "hidden away" behind the proxying code, it doesn't seem like there's an easy hack anyway.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 10, 2005 3:57 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
what about executing 2 queries? one to load b, another for c

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject: Re: Eagerly loading multiple collections
PostPosted: Fri Mar 11, 2005 2:11 pm 
Beginner
Beginner

Joined: Thu Jan 20, 2005 3:25 pm
Posts: 22
tgoorden wrote:
I've really thouroughly researched this (forum, TFM, Wiki, google and several stabs at the Hibernate source code), but to no avail. Because all the lazy loading is "hidden away" behind the proxying code, it doesn't seem like there's an easy hack anyway.


Have you tried the fetch join in HSQL? I think it would do what you want (I'm not sure I understand). If you have an object ob with a collection mycol you can eagerly load it in a HSQL query with "inner join fetch ob.mycol".

Henri.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 11, 2005 2:16 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
The correct solution is batch fetching (for now).

HB3 core implements "subselect fetching", but this is not exposed to the user for now.


Top
 Profile  
 
 Post subject: Re: Eagerly loading multiple collections
PostPosted: Fri Mar 11, 2005 3:08 pm 
Newbie

Joined: Tue Mar 01, 2005 10:37 am
Posts: 17
tgoorden wrote:
Hi, I'm working on a POC for a very large project, but we're having issues with object detachment:

Suppose you have:
Code:
Object A
+collection(B) // lazy loaded
+collection(C) // lazy loaded

basically an object with more than one collection.

Now, using Criteria, try to get a list of A objects that are complete (both collections have been loaded) and detached. For one collection, this is easy to do with setFetchMode("Bs",FetchMode.JOIN). But, there seems to be no way to do this with the collection of Cs as well.

Setting FetchMode.JOIN twice is ignored because of Cartesian product issues. FetchMode.SELECT does a secondary select (to be expected), but this is not done eagerly, so you get a LazyLoadingException anyway.

I've really thouroughly researched this (forum, TFM, Wiki, google and several stabs at the Hibernate source code), but to no avail. Because all the lazy loading is "hidden away" behind the proxying code, it doesn't seem like there's an easy hack anyway.


If you don't care about the second select (you just want to fix the LazyLoadingException), then do this:

Code:
Hibernate.initialize(collection(B));
Hibernate.initialize(collection(C));


Top
 Profile  
 
 Post subject: Re: Eagerly loading multiple collections
PostPosted: Tue Oct 11, 2005 11:45 am 
Newbie

Joined: Wed May 18, 2005 4:50 am
Posts: 18
Quote:
Setting FetchMode.JOIN twice is ignored because of Cartesian product issues. FetchMode.SELECT does a secondary select (to be expected), but this is not done eagerly, so you get a LazyLoadingException anyway.

In the javadoc (for 3.0.5) it says

Quote:
FetchMode.SELECT - Fetch eagerly, using a separate select. Equivalent to fetch="select".

Is this javadoc wrong? What does "eagerly" mean in this context. Seems to be "lazy" to me ...


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