-->
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: Eager loading of list properties
PostPosted: Fri Feb 26, 2010 5:03 am 
Beginner
Beginner

Joined: Wed Jan 16, 2008 8:16 am
Posts: 23
Hi,

I played around with eager loading in order to tune the performance.
I used 'join fetch' in hql/criteria for loading some properties eagerly.
This works quite fine.

My problem is, that I want to avoid to have a cartesian product for
collections.
A sample:

Class A {
B b;
List<C> c;
}

Class B {
}

Class C {
D d;
}

Class D {
}

It is easy to load B when loading A, just use "from A a left outer join fetch a.b".
Eager loading c is not desired, because I want avoid having a cartesian product.

So my question: Can i tell hibernate to load D eagerly when hitting the Collection
List<C> for this session in advance? I do not want to configure this fetch mode
statically in class configuration.

I'm using Hibernate 3.3.5.ga.

Best regards,
Michi


Top
 Profile  
 
 Post subject: Re: Eager loading of list properties
PostPosted: Fri Feb 26, 2010 11:36 am 
Beginner
Beginner

Joined: Tue Aug 25, 2009 11:42 am
Posts: 49
Yes use extra-lazy collections.
Firstly make A.List<C> to be a lazy collection, secondly each C to be a lazy proxy with properties not loaded and finally C.D being loaded when you need it - assuming your session is still open.


Top
 Profile  
 
 Post subject: Re: Eager loading of list properties
PostPosted: Mon Mar 01, 2010 3:09 am 
Beginner
Beginner

Joined: Wed Jan 16, 2008 8:16 am
Posts: 23
Thank you for your reply.

Almost any property in my application is lazy. I do not want to load
entities I do not needed.
I search for something like following code fragment:
Code:
A a = session.get(A.class, 1L);
Query query = session.createFilter(a.getC(), "");

// that might be the new code
query.setFetch("d", JOIN); //--> EAGER
List<C> cs = query.list();


Thanks in advance,
Michi


Top
 Profile  
 
 Post subject: Re: Eager loading of list properties
PostPosted: Mon Mar 01, 2010 11:45 am 
Beginner
Beginner

Joined: Tue Aug 25, 2009 11:42 am
Posts: 49
<bag name="..." lazy="extra"/>
Or for annotations:
@LazyCollection(LazyCollectionOption.EXTRA)

Also the use of session.load() instead of session.get() has a subtle difference which might be of advantage.


Top
 Profile  
 
 Post subject: Re: Eager loading of list properties
PostPosted: Mon Mar 01, 2010 11:49 am 
Beginner
Beginner

Joined: Tue Aug 25, 2009 11:42 am
Posts: 49
O u meant instructing Hibernate during a runtime query to load the collection lazily but load a particular class of objects referenced by each member in that collection eagerly?
I doubt u could do that.


Top
 Profile  
 
 Post subject: Re: Eager loading of list properties
PostPosted: Wed Mar 03, 2010 2:58 am 
Beginner
Beginner

Joined: Wed Jan 16, 2008 8:16 am
Posts: 23
Thanks for your reply. That's exactly what I meant.


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.