-->
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.  [ 3 posts ] 
Author Message
 Post subject: Eager loading on M:N uses inner join? Help please
PostPosted: Thu Feb 26, 2009 4:48 pm 
Newbie

Joined: Thu Feb 26, 2009 4:36 pm
Posts: 6
NHibernate 1.2
SQL Server 2005
.Net 3.5


I've got an M:N relationship and I'm querying the child associations via a ICriteria using FechMode.Eager.

The SQL being generated is doing an inner join on the associative table and then doing an left outer join on the child table. Needless to say, if there are no elements in the associative table with the parent id then the parent is not included in the results.

This is not the behavior I want. I've tried using FechMode.Join but the behavior is the same and I've read they're actually aliases for each other so that makes sense.

Is there a way to do this using the ICriteria API or will I have to resort to HQL?

Edit: I should also mention that the M:N relationship is being mapped as an IList<T>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 26, 2009 5:19 pm 
Newbie

Joined: Thu Feb 26, 2009 4:36 pm
Posts: 6
Now I'm confused. I switched to using HQL via LEFT OUTER JOIN and it's returning null.

I just want to pull all of object A out of the table, and if they have children, pull those children out as well and do it all in 1 go. If they don't have children, I still want them but with an empty list for the child list.

How do I accomplish this?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 26, 2009 6:20 pm 
Newbie

Joined: Thu Feb 26, 2009 4:36 pm
Posts: 6
Well I've answered my own question :)

CreateCriteria("parent.children", "child", NHibernate.SqlCommand.JoinType.LeftOuterJoin)

works as expected. If anyone can tell me why this isn't the default behavior, I'd love to know.


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