Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » JPA 2, problem with ORDER BY AVG
JPA 2, problem with ORDER BY AVG [message #644359] Fri, 10 December 2010 11:56 Go to next message
No real name is currently offline No real name
Messages: 3
Registered: December 2010
Junior Member
Hello all,
I have an application deployed on glassFish3 with EclipseLink as persistance Unit.

I want make a namedquery as follow :
    @NamedQuery(name = "Produits.findTop", query = "SELECT a.produit FROM Avis a GROUP BY a.produit ORDER BY avg(a.note) DESC")})

But I obtain the folowing exception :
Caused by: Exception [EclipseLink-8025] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Syntax error parsing the query [Produits.findTop: SELECT a.produit FROM Avis a GROUP BY a.produit ORDER BY avg(a.note) DESC], line 1, column 57: unexpected token [avg].
Internal Exception: NoViableAltException(10!=[1328:1: orderByItem returns [Object node] : (n= stateFieldPathExpression (a= ASC | d= DESC | ) | i= IDENT (a= ASC | d= DESC | ) );])


I don't understand why...
In contrast, the following request work perfectly but don't correspond to my need :
SELECT avg(a.note) FROM Avis a GROUP BY a.produit
SELECT a.produit FROM Avis a GROUP BY a.produit ORDER BY a.note DESC


I use the following version : EclipseLink, version: Eclipse Persistence Services - 2.0.1.v20100213-r6600

How can I correct my request? Or make a method wich do similar?

Thanks
Re: JPA 2, problem with ORDER BY AVG [message #644367 is a reply to message #644359] Fri, 10 December 2010 12:26 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris Delahunt
Messages: 1017
Registered: July 2009
Senior Member
Hello,

JPQL only supports "state_field_path_expression | result_variable" in the Order By clause, but EclipseLink added support for this in the 2.1 version through enhancement
https://bugs.eclipse.org/bugs/show_bug.cgi?id=219814

So you will need to try a later version to get this to work.

Best Regards,
Chris
Re: JPA 2, problem with ORDER BY AVG [message #644520 is a reply to message #644367] Sun, 12 December 2010 16:09 Go to previous message
No real name is currently offline No real name
Messages: 3
Registered: December 2010
Junior Member
Hello,
Thanks for your answer!
But I have an another problem, on my dev system, i can update my glassfish server, but I don't have the right to modify the production server (secuirty blablabla...) and the administrator don't want to update EclipseLink...
Is it a way to embed the new version of EclipseLink with the EJB?
I'm currently using maven, and netbeans.

Thanks in advance!
Previous Topic:dbws response type
Next Topic:Querying a table with an array column fails
Goto Forum:
  


Current Time: Sat Aug 23 05:44:07 EDT 2014

Powered by FUDForum. Page generated in 0.02590 seconds