-->
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: A better approach: one-to-many parent-child ...
PostPosted: Wed Dec 07, 2005 1:05 pm 
Regular
Regular

Joined: Wed Aug 25, 2004 7:40 pm
Posts: 65
I have a class, called A, with one-to-many parent-child relationship with its child, called B. I need to retrieve a list of A met specific conditions. Not all attributes of A need to be displayed in the list, nor the attributes of the B class, but some statistic data of B class such as the count, the average of one attribute value, etc. With the transfer data object approach, I can have two approaches with the A's children class B: fetch all its children B and write some methods of the TDO to get those statistic data, or apply the HQL aggregate functions in the HQL.

Which approach is better?

Thanks for your inputs.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 07, 2005 1:09 pm 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
use HQL, you can use the databases algorithms for the aggregates (which are ways more effective that iterating back and forth in your code)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 07, 2005 1:30 pm 
Regular
Regular

Joined: Wed Aug 25, 2004 7:40 pm
Posts: 65
MikePloed wrote:
use HQL, you can use the databases algorithms for the aggregates (which are ways more effective that iterating back and forth in your code)


Thanks for your input, Mike.

The calculation the statistis data is not necessary using iterators to walk over the data, at least from the API. The count, for example, can be obtained by size method of the collection class.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 07, 2005 1:39 pm 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
of course but a database will always be more efficient at these kinds of things. in addition to that you are able to reduce the memory footprint of your app since you dont have to load all the objects into memory.


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.