subqueryjdodatanucleusjdoql

Is it possible to refer to the outer query from a subquery filter string?


From the subquery filter I refer to the outer query this way:

type.maxZoneTests > this.fromZone

Query freeZoneSubquery = pm.newQuery(Zone.class, sb.toString());
freeZoneSubquery.setResult("ip.trim()");
outerQuery.addSubquery(freeZoneSubquery, "List reservedZones", null);

But when I execute the main query, I get the following errors:

javax.jdo.JDOUserException: Query has reference to member "fromZone" of class "com.mg.ipk.Zone" yet this doesnt exist!
    at org.datanucleus.api.jdo.NucleusJDOHelper.getJDOExceptionForNucleusException(NucleusJDOHelper.java:519)
    at org.datanucleus.api.jdo.JDOQuery.executeWithArray(JDOQuery.java:321)
    at com.ipkzen.ta.core.services.dao.ProcedureExecutionRecordDAOImpl.getEligibleTests(ProcedureExecutionRecordDAOImpl.java:83)
    at com.ipkzen.ta.core.services.dao.ProcedureExecutionRecordDAOImpl.main(ProcedureExecutionRecordDAOImpl.java:325)
NestedThrowablesStackTrace:
Query has reference to member "fromZone" of class "com.mg.ipk.Zone" yet this doesnt exist!
org.datanucleus.exceptions.NucleusUserException: Query has reference to member "fromZone" of class "com.mg.ipk.Zone" yet this doesnt exist!
    at org.datanucleus.store.rdbms.query.QueryToSQLMapper.getSQLTableMappingForPrimaryExpression(QueryToSQLMapper.java:2262)
    at org.datanucleus.store.rdbms.query.QueryToSQLMapper.processPrimaryExpression(QueryToSQLMapper.java:2114)
    at org.datanucleus.query.evaluator.AbstractExpressionEvaluator.compilePrimaryExpression(AbstractExpressionEvaluator.java:180)
    at org.datanucleus.query.evaluator.AbstractExpressionEvaluator.compileUnaryExpression(AbstractExpressionEvaluator.java:169)
    at org.datanucleus.query.evaluator.AbstractExpressionEvaluator.compileAdditiveMultiplicativeExpression(AbstractExpressionEvaluator.java:148)
    at org.datanucleus.query.evaluator.AbstractExpressionEvaluator.compileRelationalExpression(AbstractExpressionEvaluator.java:123)
    at org.datanucleus.query.evaluator.AbstractExpressionEvaluator.compileOrAndExpression(AbstractExpressionEvaluator.java:65)
    at org.datanucleus.query.evaluator.AbstractExpressionEvaluator.evaluate(AbstractExpressionEvaluator.java:46)
    at org.datanucleus.query.expression.Expression.evaluate(Expression.java:337)
    at org.datanucleus.query.expression.DyadicExpression.evaluate(DyadicExpression.java:70)
    at org.datanucleus.query.expression.DyadicExpression.evaluate(DyadicExpression.java:70)
    at org.datanucleus.store.rdbms.query.QueryToSQLMapper.compileFilter(QueryToSQLMapper.java:461)
    at org.datanucleus.store.rdbms.query.QueryToSQLMapper.compile(QueryToSQLMapper.java:381)
    at org.datanucleus.store.rdbms.query.QueryToSQLMapper.processVariableExpression(QueryToSQLMapper.java:3275)
    at org.datanucleus.store.rdbms.query.QueryToSQLMapper.processInvokeExpression(QueryToSQLMapper.java:2745)
    at org.datanucleus.query.evaluator.AbstractExpressionEvaluator.compilePrimaryExpression(AbstractExpressionEvaluator.java:200)
    at org.datanucleus.query.evaluator.AbstractExpressionEvaluator.compileUnaryExpression(AbstractExpressionEvaluator.java:169)
    at org.datanucleus.query.evaluator.AbstractExpressionEvaluator.compileAdditiveMultiplicativeExpression(AbstractExpressionEvaluator.java:148)
    at org.datanucleus.query.evaluator.AbstractExpressionEvaluator.compileRelationalExpression(AbstractExpressionEvaluator.java:123)
    at org.datanucleus.query.evaluator.AbstractExpressionEvaluator.compileOrAndExpression(AbstractExpressionEvaluator.java:65)
    at org.datanucleus.query.evaluator.AbstractExpressionEvaluator.evaluate(AbstractExpressionEvaluator.java:46)
    at org.datanucleus.query.expression.Expression.evaluate(Expression.java:337)
    at org.datanucleus.query.expression.DyadicExpression.evaluate(DyadicExpression.java:67)
    at org.datanucleus.query.expression.DyadicExpression.evaluate(DyadicExpression.java:70)
    at org.datanucleus.query.expression.DyadicExpression.evaluate(DyadicExpression.java:67)
    at org.datanucleus.query.expression.DyadicExpression.evaluate(DyadicExpression.java:67)
    at org.datanucleus.query.expression.DyadicExpression.evaluate(DyadicExpression.java:67)
    at org.datanucleus.query.expression.DyadicExpression.evaluate(DyadicExpression.java:67)
    at org.datanucleus.query.expression.DyadicExpression.evaluate(DyadicExpression.java:67)
    at org.datanucleus.query.expression.DyadicExpression.evaluate(DyadicExpression.java:67)
    at org.datanucleus.query.expression.DyadicExpression.evaluate(DyadicExpression.java:67)
    at org.datanucleus.query.expression.DyadicExpression.evaluate(DyadicExpression.java:67)
    at org.datanucleus.query.expression.DyadicExpression.evaluate(DyadicExpression.java:67)
    at org.datanucleus.store.rdbms.query.QueryToSQLMapper.compileFilter(QueryToSQLMapper.java:461)
    at org.datanucleus.store.rdbms.query.QueryToSQLMapper.compile(QueryToSQLMapper.java:381)
    at org.datanucleus.store.rdbms.query.JDOQLQuery.compileQueryFull(JDOQLQuery.java:883)
    at org.datanucleus.store.rdbms.query.JDOQLQuery.compileInternal(JDOQLQuery.java:343)
    at org.datanucleus.store.query.Query.executeQuery(Query.java:1747)
    at org.datanucleus.store.query.Query.executeWithArray(Query.java:1666)
    at org.datanucleus.api.jdo.JDOQuery.executeWithArray(JDOQuery.java:312)
    at com.ipkzen.ta.core.services.dao.ProcedureExecutionRecordDAOImpl.getEligibleTests(ProcedureExecutionRecordDAOImpl.java:83)
    at com.ipkzen.ta.core.services.dao.ProcedureExecutionRecordDAOImpl.main(ProcedureExecutionRecordDAOImpl.java:325)

I can workaround this only If I can perform a join but I know that JDO doesn't allow declaring imports, variables nor parameters for subqueries !


Solution

  • The JDO spec and DN docs define all of that well enough http://www.datanucleus.org/products/accessplatform_3_1/jdo/jdoql_subquery.html