-->
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.  [ 5 posts ] 
Author Message
 Post subject: Bidirectional 1-M relationship Query
PostPosted: Fri Dec 02, 2005 9:48 pm 
Regular
Regular

Joined: Tue May 31, 2005 9:55 am
Posts: 67
If I have a bidirectional 1-M relationship that is lazy.

[1] Order <--> [Many] Requirements

When I retrieve the Order (either though Load or Query), NHibernate issues a SQL query to retrieve the non-lazy properties.

When I iterate over each Requirement in the Order, NHibernate issues a SQL query for the non-lazy properties of a Requirement. However, since Requirement has a backward reference to Order, it also joins all the Order properties in the Query. Why does it do this, since the Order is already loaded in the Session. Is there a way to prevent this.

Thanks,
craig


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 05, 2005 11:29 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Do you have outer-join or fetch specified on the Order's Requirement property? You can use an HQL query to override this behavior.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 05, 2005 2:45 pm 
Regular
Regular

Joined: Tue May 31, 2005 9:55 am
Posts: 67
outer-join is true. Are you suggesting set it to false since the parent must be present? What exactly will be the effect of setting outer-join to false in this case?

thanks,
craig


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 05, 2005 5:00 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Yes, outer-join is what causes the join since NHibernate doesn't try to deduce whether the parent is or isn't loaded already. If you set it to false, then every time you try to load a child it will just select from the child table and won't add a join to parent. Once again, if you will need to override this in some specific case, you can do so using an HQL or criteria query.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 05, 2005 5:24 pm 
Regular
Regular

Joined: Tue May 31, 2005 9:55 am
Posts: 67
Thanks.

That makes perfect sense and is very helpful advice.

craig


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