-->
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: Can someone show me how to do a group by clause query?
PostPosted: Tue Oct 05, 2004 12:15 pm 
Newbie

Joined: Tue Sep 14, 2004 1:35 pm
Posts: 9
I need an query example to do something like this

SELECT taskno, count(taskno) from ACTIVITY group by taskno order by taskno

Where ACTIVITY has a composite id in a ACTIVITYPK java class that is made up of these three properties: userid, date & taskno

How do I tell Hibernate that taskno is a property of ACTIVITYPK?

Here is the trace log:
[9/29/04 11:45:41:699 EDT] 15f7df77 EvaluationDAO I com.test.dao.hibernate.EvaluationDAOHibernate get all activities:
[9/29/04 11:45:41:761 EDT] 15f7df77 DispatcherSer E org.springframework.web.servlet.DispatcherServlet Could not complete request
[9/29/04 11:45:41:777 EDT] 15f7df77 DispatcherSer E org.springframework.web.servlet.DispatcherServlet TRAS0014I: The following exception was logged org.springframework.orm.hibernate.HibernateQueryException: undefined alias: taskNo [select taskNo, count(taskNo) from com.test.model.Activity group by taskNo order by taskNo]; nested exception is net.sf.hibernate.QueryException: undefined alias: taskNo [select taskNo, count(taskNo), from com.test.model.Activity group by taskNo order by taskNo]
net.sf.hibernate.QueryException: undefined alias: taskNo [select taskNo, count(taskNo) from com.test.model.Activity group by taskNo order by taskNo]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 05, 2004 1:32 pm 
Senior
Senior

Joined: Sun Jan 04, 2004 2:46 pm
Posts: 147
Assuming ACTIVITY has a taskno property then you need to do this..

Code:
SELECT act.taskno, count(act.taskno) from ACTIVITY act group by act.taskno order by act.taskno


Every property must have the object alias qualified in front of it. It isn't like SQLServer which will work it out for you if possible.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 05, 2004 1:42 pm 
Newbie

Joined: Tue Sep 14, 2004 1:35 pm
Posts: 9
The problem is taskno is not a property of ACTIVITY. taskno is a property of ACTIVITYPK which is a composite id for ACTIVITY.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 05, 2004 5:10 pm 
Newbie

Joined: Tue Sep 14, 2004 1:35 pm
Posts: 9
Nevermind, I got it working. Just have to quality every property with the corresponding object alias.


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.