eclipse-ee4j / eclipselink

Eclipselink project
https://eclipse.dev/eclipselink/
Other
197 stars 168 forks source link

Unable to omit optional entity identification variable from arguments to built-in aggregate functions #2192

Closed ajaypaul-ibm closed 2 days ago

ajaypaul-ibm commented 2 months ago

When attempting to invoke aggregate functions in JPQL and supplying an argument that omits the optional entity identification variable, such as,

SELECT MAX(price) FROM Item
SELECT MIN(price) FROM Item
SELECT AVG(price) FROM Item

EclipseLink is rejecting the JPQL claiming there is a syntax error,


Caused by: java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: 
Exception Description: Syntax error parsing [SELECT MAX(price) FROM Item]. 
[11, 16] The encapsulated expression is not a valid expression.
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1848)
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1869)
    at io.openliberty.data.internal.persistence.RepositoryImpl.invoke(RepositoryImpl.java:871)
    ... 38 more
Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services - 5.0.0-B02.v202404111748): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Syntax error parsing [SELECT MAX(price) FROM Item]. 
[11, 16] The encapsulated expression is not a valid expression.
    at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildException(HermesParser.java:169)
    at org.eclipse.persistence.internal.jpa.jpql.HermesParser.validate(HermesParser.java:345)
    at org.eclipse.persistence.internal.jpa.jpql.HermesParser.populateQueryImp(HermesParser.java:292)
    at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildQuery(HermesParser.java:174)
    at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:144)
    at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:120)
    at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:107)
    at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:91)
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1846)
    ... 40 more
Riva-Tholoor-Philip commented 3 weeks ago

I am looking in to this issue

rfelcman commented 1 day ago

Hello, You can verify fixes in the latest snapshots from 5.0.0-20240911.143118-65 or 5.0.0-B03 from the Maven Central.