Search code examples
javajpaeclipselinkjpql

Invalid query key thrown because of JPQL statement in eclipselink 2.5.2 but works in 2.3.2


I have the following JQPL query:

SELECT e FROM Emp e WHERE SIZE(e.companyBean.emps) > 0

The problem is that it didn't work on eclipselink 2.5.2, when I tried it on 2.3.2 it worked successfully

I thought that there maybe some changes in JPA that disallow this path navigation but couldn't find anything on the web.

So is there something wrong about this query or changes in eclipselink that may be the cause of this exception ??

Thanks

The whole maven project: https://github.com/mohamedkomalo/jpa2-eclipselink/

The Emp entity: https://github.com/mohamedkomalo/jpa2-eclipselink/blob/master/src/main/java/model/Emp.java

The Company entity: https://github.com/mohamedkomalo/jpa2-eclipselink/blob/master/src/main/java/model/Company.java

The exception

Exception in thread "main" Local Exception Stack: 
Exception [EclipseLink-6015] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.QueryException
Exception Description: Invalid query key [
Query Key emps
   Base model.Emp{DatabaseTable(t0)=DatabaseTable(emp)}] in expression.
Query: ReadAllQuery(name="Emp.findEmployeesInBigCompanies" referenceClass=Emp jpql="SELECT e FROM Emp e WHERE SIZE(e.companyBean.emps) > 0")
    at org.eclipse.persistence.exceptions.QueryException.invalidQueryKeyInExpression(QueryException.java:697)
    at org.eclipse.persistence.internal.expressions.ObjectExpression.getDescriptor(ObjectExpression.java:453)
    at org.eclipse.persistence.internal.expressions.SubSelectExpression.normalizeSubSelect(SubSelectExpression.java:186)
    at org.eclipse.persistence.internal.expressions.ExpressionNormalizer.normalizeSubSelects(ExpressionNormalizer.java:114)
    at org.eclipse.persistence.internal.expressions.SQLSelectStatement.normalize(SQLSelectStatement.java:1534)
    at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.buildNormalSelectStatement(ExpressionQueryMechanism.java:549)
    at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.prepareSelectAllRows(ExpressionQueryMechanism.java:1720)
    at org.eclipse.persistence.queries.ReadAllQuery.prepareSelectAllRows(ReadAllQuery.java:813)
    at org.eclipse.persistence.queries.ReadAllQuery.prepare(ReadAllQuery.java:744)
    at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:661)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.checkPrepare(ObjectLevelReadQuery.java:901)
    at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:613)
    at org.eclipse.persistence.internal.jpa.QueryImpl.getDatabaseQueryInternal(QueryImpl.java:341)
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1124)
    at practicies.Day2.runPractice3(Day2.java:58)
    at practicies.Day2.main(Day2.java:22)

Solution

  • Looks like a bug in creating a subquery over the companyBean relationship. A workaround might be to specify the join outside of the SIZE function, i.e. SELECT e FROM Emp e join e.companyBean companyBean WHERE SIZE(companyBean.emps) > 0.