-->
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: Batch Fetching (parent->children)
PostPosted: Mon May 16, 2005 12:06 am 
Newbie

Joined: Sun May 15, 2005 11:39 pm
Posts: 17
Location: Australia
Hi All,

A few weeks ago, I posted a question about "batch fetching" support (http://sourceforge.net/forum/message.php?msg_id=3110550).

The solution suggested to me was to use "from Parent p left join fetch p.Children" syntax in a query.

This pretty much achieves what I need in terms of reducing the SQL calls to one, however it introduces a new problem.

With regards to the following query,

Code:
IList   orders = ses1.Find("from clsOrderHeader o left join fetch o.OrderDetails");


Lets say that there are 3 'header' rows, each one having say '5' children. The resulting orders IList will contain 15 clsOrderHeader objects. Basically, 5 instances of each one (ie one for each detail row).

Can someone please tell me if this is expected behaviour? Is there a way to reduce it to the correct amount? Should I be manually filtering it?

For brevity, I've not included my hbm.xml files but obviously am more than happy to if it will help. I don't think that this is the problem though because, when I use 'normal' CreateCriteria sytax, the code runs fine.

Thanks very much for your help.



Damien Sawyer


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 16, 2005 1:58 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Yes, this is how Java Hibernate behaves too - essentially it translates the rows returned by the database query into objects. That SQL query returns 15 rows, so you get 15 objects in the list (but only 3 of them distinct). You have to filter the result set manually (using an ISet for example).


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 16, 2005 4:23 am 
Newbie

Joined: Sun May 15, 2005 11:39 pm
Posts: 17
Location: Australia
Thanks Sergey


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 27, 2005 12:00 am 
Nice feature, HQL is powerful.

I had/have the same problem as damien but I go another level into the hierarchy.

What I was trying to do is:

<b>HQL</b>: from Grandparent Grandparent left join fetch Grandparent.Parent Parent left join fetch Parent.Children

This results in the correct SQL query but NHibernate seems to not set Gradparent's Parent property whereas a simple 'from Parent Parent left join fetch Parent.Children' would.

Any ideas?


Top
  
 
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.