-->
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: General question about fetch depth and eager fetching.
PostPosted: Thu Mar 02, 2006 11:29 am 
Newbie

Joined: Tue Jun 07, 2005 10:46 am
Posts: 15
This is just a general question about hibernate capability. If one had a series of objects with the following relationship scenerio: A has many to one to B which has a many to one to C which has many to one to D which has many to one to E and the fetching for all these associations is set to eager in the hbm files. Is it possible in hibernate to stop the eager fetching say at the second level. I know there is a fetch depth property in the hibernate.properties file, but all that seems to do is consolidate the sql generated into larger and larger sql as the fetch depth setting is increased. So I don't think that is the way to do it. The thing is for any one of these objects I would like to eagerly get the next object, but if I start at object A I only want B, but not C,D, and E. And if I start at C, I only want D. Can this be controlled somehow?

Mike

I need to add that I am using HQL and not detached criteria. I saw a post earlier of how to do this with DetachedCriteria, but that won't fit my situation. I'd be okay with paying for consulting services to find a solution if its at all possible to do this with HQL.

_________________
M Connolly


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 02, 2006 6:48 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
You can use max_fetch_depth, but that doesn't seem to affect explicit join fetches. Works great on select fetches though.

Using only HQL, you'd be better off adopting the opposite approach. Set up your mapping to always lazily load, then have different queries to override this setting using join fetch, when appropriate. So if you wanted just A and B, you'd have
Code:
select a from A a join fetch a.B b
That would eagerly load A and B, and lazily load everything else. For a full eager load, use a different query
Code:
select a from A a
join fetch a.B b
join fetch b.C c
join fetch c.D d
join fetch d.E
That would eagerly load the entire graph.


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.