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.  [ 1 post ] 
Author Message
 Post subject: Best way to get count of sub-objects?
PostPosted: Fri Jun 15, 2007 1:57 pm 
Newbie

Joined: Tue Feb 06, 2007 5:46 am
Posts: 10
I have a set of Items organized by Category and I want to get a count of Items per Category for display on a web page.

This is a VERY simplified table structure:

=======
Category
-----------
CategoryID (PK)
Name
URL (UK)
=======

========
Item
----------
ItemID (PK)
CategoryID (FK)
IsPublished
ItemType (enum, vals are A, B, and C)
=========

So, I have one page for each ItemType with a list of all Categories. The list is just the names linked to a page that shows all Items in that Category whose ItemType matches the page it came from and where IsPublished is 1 (true). So the category page URL might be /Category.aspx?ItemType=B and the page with the list of items might be /Category.aspx?ItemType=B&CategoryID=42

What I want to be able to do is on the category list page (/Category.aspx?ItemType=B) be able to put the number of Items in parenthesis next to the category name link.

I know there are several ways to do this and my problem is not getting it done. My problem is I'm not sure which way is the correct/best way to do it.

Ways I have thought of to solve this problem:

1. Direct SQL query

2. HQL query

3. Add three properties to the Category object: CountOfItemTypeA, CountOfItemTypeB, and CountOfItemTypeC. The load the counts in the mapping for the Category object. (Before you balk at this, A, B, and C are definitely the only possible values. It would take a huge shift in the business for this situation to change and so I am comfortable with doing it this way.)

4. Possibly use a Criteria query??

5. My Category object already has a bag of ItemTypeAList, etc. Does it work to just do Category.ItemTypeAList.Count or is that inefficient?

6. Any better solutions out there???

So, what do you think the best overall solution to this problem is?

TIA

_________________
Josh Coady
http://jlcoady.net/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.