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 method to execute multiple counts in select
PostPosted: Wed Apr 04, 2007 12:20 pm 
Beginner
Beginner

Joined: Wed Nov 29, 2006 12:23 pm
Posts: 42
I have an entity model with a parent child relationship. I'd like to be able to retrieve a number of attributes for the parent, and also a number of counts for different criteria of the children. What's the best way to go about this?

Is there any way this can be done with HQL, or am I better off just using createSQLQuery()? Or even just to do it at the entity level (with attributes/methods on my parent entity to "GetCountOfChildrenWhere(Criteria criteria)"

I would like to be able to do something like the following SQL

Code:
SELECT       p.id,
             p.name,
             SUM(CASE c.Status WHEN 'Open' THEN 1 ELSE 0 END) AS Open,
             SUM(CASE c.Status WHEN 'Closed' THEN 1 ELSE 0 END) AS Closed
from parent, child
where parent.id = child.parentid


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.