Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] JPQL + LIKE + Subquery = MismatchedTokenException

Hi,

I'm trying to execute the following JPQL against a Derby database using eclipse link 1.0.2

SELECT COUNT(j.jobName) FROM Job j WHERE (((j.lineage LIKE (SELECT j.filterLineage FROM Job j WHERE j.jobName = '100_box' AND j.server = 'server-nc0')) AND j.server = 'server-nc0')) AND (j.jobType<>'BOX')

<skip if you are not interested in the rational of the query>

The idea here is to get a set of jobs that reside underneath the lineage path that the parent is located in.  For example, a containing node, a box, may have a lineage of '/' meaning that it is at the top.  This box has an ID of 100, and sub nodes of this box will have a lineage of '/100/'.  At the time that this query is constructed all that is known is the box name.  Therefore all sub nodes of this box need to be gathered in terms of the box name.  To assist this query, a second field filterLineage is defined that has the form '/100/%'.  This "AND j.server =..." you see twice in the query is necessary to scope certain portions of the query to only operate on one server.  More than likely this query will be operation against multiple servers at the same time.

</skip>

Executing this query causes a MismatchedTokenException in eclipse link.

Exception Description: Syntax error parsing the query [SELECT COUNT(j.jobName) FROM Job j WHERE (((j.lineage LIKE (SELECT j.filterLineage FROM Job j WHERE j.jobName = '100_box' AND j.server = 'server-nc0')) AND j.server = 'server-nc0')) AND (j.jobType<>'BOX')], line 1, column 61: syntax error at [LIKE].
Internal Exception: MismatchedTokenException(37!=70)
    at org.eclipse.persistence.exceptions.JPQLException.syntaxErrorAt(JPQLException.java:355)
    at org.eclipse.persistence.internal.jpa.parsing.jpql.JPQLParser.handleRecognitionException(JPQLParser.java:304)
    at org.eclipse.persistence.internal.jpa.parsing.jpql.JPQLParser.addError(JPQLParser.java:245)
    at org.eclipse.persistence.internal.jpa.parsing.jpql.JPQLParser.reportError(JPQLParser.java:362)
    at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.arithmeticPrimary(JPQLParser.java:8904)
    at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.arithmeticFactor(JPQLParser.java:8620)
    at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.arithmeticTerm(JPQLParser.java:8444)
    at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.simpleArithmeticExpression(JPQLParser.java:8351)
    at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.arithmeticPrimary(JPQLParser.java:8890)
    at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.arithmeticFactor(JPQLParser.java:8620)
    at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.arithmeticTerm(JPQLParser.java:8444)
    at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.simpleArithmeticExpression(JPQLParser.java:8351)
    at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.arithmeticPrimary(JPQLParser.java:8890)
    at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.arithmeticFactor(JPQLParser.java:8620)
    at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.arithmeticTerm(JPQLParser.java:8444)
    at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.simpleArithmeticExpression(JPQLParser.java:8351)
    at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.arithmeticExpression(JPQLParser.java:8292)
    at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.simpleConditionalExpression(JPQLParser.java:7039)
    at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.conditionalPrimary(JPQLParser.java:6997)
    at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.conditionalFactor(JPQLParser.java:2989)
    at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.conditionalTerm(JPQLParser.java:2879)
    at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.conditionalExpression(JPQLParser.java:2805)
    at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.whereClause(JPQLParser.java:2762)
    at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.selectStatement(JPQLParser.java:356)
    at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.document(JPQLParser.java:261)
    at org.eclipse.persistence.internal.jpa.parsing.jpql.JPQLParser.parse(JPQLParser.java:133)
    at org.eclipse.persistence.internal.jpa.parsing.jpql.JPQLParserFactory.parseEJBQLString(JPQLParserFactory.java:33)
    at org.eclipse.persistence.internal.jpa.parsing.jpql.JPQLParserFactory.populateQuery(JPQLParserFactory.java:51)
    at org.eclipse.persistence.queries.JPQLCall.populateQuery(JPQLCall.java:177)
    at org.eclipse.persistence.internal.queries.JPQLCallQueryMechanism.buildSelectionCriteria(JPQLCallQueryMechanism.java:68)
    at org.eclipse.persistence.queries.DatabaseQuery.buildSelectionCriteria(DatabaseQuery.java:347)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.prePrepare(ObjectLevelReadQuery.java:1641)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.checkPrePrepare(ObjectLevelReadQuery.java:632)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.checkEarlyReturn(ObjectLevelReadQuery.java:567)
    at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:615)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:840)
    at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:456)
    at org.eclipse.persistence.internal.sessions.AbstractSession.internalExecuteQuery(AbstractSession.java:2207)
    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1178)
    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1162)
    at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1108)
    ...
Caused by: MismatchedTokenException(37!=70)
    at org.eclipse.persistence.internal.libraries.antlr.runtime.BaseRecognizer.mismatch(Unknown Source)
    at org.eclipse.persistence.internal.libraries.antlr.runtime.BaseRecognizer.match(Unknown Source)
    at org.eclipse.persistence.internal.jpa.parsing.jpql.antlr.JPQLParser.arithmeticPrimary(JPQLParser.java:8893)

My question is, should this type of query be valid with JPQL?  If this is valid and this is not a bug how should it be written?  I know I can go to an ij prompt of Derby and type in the following query against the same database and it works.

SELECT COUNT(j.job_name) FROM m_job j WHERE (((j.lineage LIKE (SELECT j.flineage FROM m_job j WHERE j.job_name = '100_box' AND j.server = 'server-nc0')) AND j.server = 'server-nc0')) AND (j.type<>'BOX');


Thanks,
Jed

Back to the top