-->
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.  [ 3 posts ] 
Author Message
 Post subject: setting GROUP BY clause for many attributes
PostPosted: Wed Feb 04, 2004 10:14 am 
Newbie

Joined: Tue Jan 06, 2004 8:06 am
Posts: 13
Hi all

Emphasize on group by clause, are there alternative to following query (where all cat attributes are explicitly specified)?

catList = db.find("select cat, sum(weight) from cat in class eg.Cat where cat.color='white' group by cat.id, cat.birthdate, cat.color, cat.sex, cat.weight");


Quite a few occasions I am required to return the object itself with the aggregate values and the object can have more than 10 attributes easily.


I also noted that following query work fine in MySQL but not in Oracle as Oracle require every displayed column to be specified in group by clause.

catList = db.find("select cat, sum(weight) from cat in class eg.Cat where cat.color='white' group by cat.sex");


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2004 10:20 am 
Newbie

Joined: Tue Jan 06, 2004 8:06 am
Posts: 13
My current alternative is to split it to 2 queries as follow:

result = db.find("select cat.id, sum(weight) from cat in class eg.Cat where cat.color='white' group by cat.sex");

for(Iterator itr=result.iterator(); result.hasNext(); ) {

Object[] row = (Object[]) itr.next();
Cat cat = (Cat) db.load(Cat.class, (String)row[0]);
.
.
.
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2004 10:43 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
FAQ: http://www.hibernate.org/74.html#A10


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