jQuery in Action, 3rd edition
The moose likes EJB and other Java EE Technologies and the fly likes what is wrong in following EJBQL?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "what is wrong in following EJBQL??" Watch "what is wrong in following EJBQL??" New topic

what is wrong in following EJBQL??

Pras Tiwari
Ranch Hand

Joined: Nov 07, 2005
Posts: 186
I am developing My application using CMP EJB2.1 Spec.
In one of my entity bean I am writing followinf EJB QL in my EJB-SELECT Query:-
SELECT COUNT(userid) FROM OrderMaster as o GROUP BY o.userid

But when I am deploying under my app server (JBOSS4.0.3), I am getting following error:-
15:05:27,328 INFO [STDOUT] javax.ejb.FinderException: Error compiling ejbql: org.jboss.ejb.plugins.cmp.ejbql.ParseException: Encountered "GROUP" at line 1, column 44.
Was expecting one of:
"," ...

15:05:27,328 INFO [STDOUT] at org.jboss.ejb.plugins.cmp.jdbc.JDBCDynamicQLQuery.execute(JDBCDynamicQLQuery.java:101)

Where is the problem??
Please help me.
Thank you.

********Deserve Before You Desire********
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Well just basic querying is that if you have an aggregate you don't group by that aggregate field. You only GROUP BY on the fields that aren't aggregates.

For example

Select a, b, COUNT(c) from atable GROUP BY a, b

In the above a and b have to have a group by, but "c" which is inside the aggregate function COUNT should not be.

Remove the GROUP BY in your query and it should work. Also in your COUNT prefix userid with "o." your object alias.


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
I agree. Here's the link: http://aspose.com/file-tools
subject: what is wrong in following EJBQL??
It's not a secret anymore!