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.  [ 4 posts ] 
Author Message
 Post subject: How to use multi-level, deep, fetch join in complex queries?
PostPosted: Thu Jun 26, 2008 9:24 am 
Newbie

Joined: Thu Jun 26, 2008 9:11 am
Posts: 2
Hi guys,
I'm pretty new to NHibernate, and I need some help. I'm using the latest release of NH, and I'm querying SQL Server 2005.

My tables and entities have the following structure:

Portal
....Id
....Names (Dictionary<string, string>)
....Settings (Dictionary<string, string>)
....Tabs (List<Tab>)
........Id
........Name
........Names (Dictionary<string, string>)
........Settings (Dictionary<string, string>)
........Modules (List<Module>)
............Id
............Name
............Settings (Dictionary<string, string>)
............Names (Dictionary<string, string>)

I'm trying to use a fetch-join query to get all the data in a single query, because I immediately need all data (I'll return it to the front-end server, via WCF). The query is as follows:

Portal p = hb.Session.CreateCriteria(typeof(Portal))
.Add(Expression.Eq("Id", Id))
.SetFetchMode("Tabs", FetchMode.Join)
.SetFetchMode("Settings", FetchMode.Join)
.SetFetchMode("Modules", FetchMode.Join)
.SetFetchMode("Names", FetchMode.Join)
.UniqueResult<Portal>();

What I noticed is the the Tabs and Modules child collections are filled immediately, while the Names and Settings collections are not, they are lazy loaded. Might it be that's because I have collections with the same names at various levels, and NHibernate doesn't know to which of them it should apply the fetch-join?

Can you suggest a way to run a single query and fill the entire data tree? Thanks a lot for your support.
Cheers,
- Marco


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 13, 2008 6:28 pm 
Newbie

Joined: Fri Jun 29, 2007 1:28 am
Posts: 2
I'm BUMPING this, I have the same exact question.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 14, 2008 1:01 am 
Beginner
Beginner

Joined: Wed Mar 14, 2007 12:35 pm
Posts: 24
Check your max fetch depth in the config. I think by default it is 3. The depth that you are searching is 4th level which may explain the issue.

From documentation:
hibernate.max_fetch_depth - Set a maximum "depth" for the outer join fetch tree for single-ended associations (one-to-one, many-to-one). A 0 disables default outer join fetching.
eg. recommended values between 0 and 3


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 14, 2008 1:35 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
FetchMode.Join is non-lazy, but I don't know what happens if you combine it with a lazy attribute on the collection. Maybe it's ignored then.
There may also be a problem if you use bags. In that case you can't fetch the items with joins because hibernate can't decide if the duplicate objects that a returned through the join are real (which is allowed in a bag) or because of the join.

_________________
--Wolfgang


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