aspose file tools*
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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
Author

what is wrong in following EJBQL??

Pras Tiwari
Ranch Hand

Joined: Nov 07, 2005
Posts: 186
Hi,
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:
<EOF>
"," ...

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.
Pras


********Deserve Before You Desire********
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: what is wrong in following EJBQL??
 
Similar Threads
mssqlds not bound and throws NameNotFoundException
EJB QL
"declared-sql" query problem in jbosscmp-jdbc.xml...
Problem with nullable enum fields + Hibernate 3
Facing badly with "java.lang.OutOfMemoryError: Java heap space" issue on JBoss Application server