Uploaded image for project: 'OpenJPA'
  1. OpenJPA
  2. OPENJPA-2572

Parentheses before an IN operator causes a parser exception.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Not A Problem
    • 2.2.3, 2.4.0
    • None
    • sql
    • None

    Description

      I have recreated a simple version of a more complex query which is not working. Take these two queries which work fine and as expected:

      em.createQuery("select m from MyEntity2 m WHERE (m.id = 1)");
      em.createQuery("select m from MyEntity2 m WHERE m.id IN (1,2,5)");

      Now take this query and note the parentheses around m.id:

      em.createQuery("select m from MyEntity2 m WHERE (m.id) IN (1,2,5)");

      This yields the following exception:

      Caused by: <openjpa-2.2.3-SNAPSHOT-r422266:1655221M nonfatal user error> org.apache.openjpa.persistence.ArgumentException: Encountered "m . id ) IN" at character 34, but expected: ["(", ")", "*", "+", "-", ".", "/", ":", "<", "<=", "<>", "=", ">", ">=", "?", "ABS", "ALL", "AND", "ANY", "AS", "ASC", "AVG", "BETWEEN", "BOTH", "BY", "CONCAT", "COUNT", "CURRENT_DATE", "CURRENT_TIME", "CURRENT_TIMESTAMP", "DELETE", "DESC", "DISTINCT", "EMPTY", "ESCAPE", "EXISTS", "FETCH", "FROM", "GROUP", "HAVING", "IN", "INNER", "IS", "JOIN", "LEADING", "LEFT", "LENGTH", "LIKE", "LOCATE", "LOWER", "MAX", "MEMBER", "MIN", "MOD", "NEW", "NOT", "NULL", "OBJECT", "OF", "OR", "ORDER", "OUTER", "SELECT", "SET", "SIZE", "SOME", "SQRT", "SUBSTRING", "SUM", "TRAILING", "TRIM", "TYPE", "UPDATE", "UPPER", "WHERE", <DATE_LITERAL>, <DECIMAL_LITERAL>, <IDENTIFIER>, <INTEGER_LITERAL>, <STRING_LITERAL2>, <STRING_LITERAL>, <TIMESTAMP_LITERAL>, <TIME_LITERAL>].
      at org.apache.openjpa.kernel.jpql.JPQL.generateParseException(JPQL.java:13180)
      at org.apache.openjpa.kernel.jpql.JPQL.jj_consume_token(JPQL.java:13054)
      at org.apache.openjpa.kernel.jpql.JPQL.conditional_primary(JPQL.java:1980)
      ........

      Looks like something in our parser doesn't expect this.

      Oh, BTW, the answer is not to simply remove the parentheses......ultimately what we want to do is something more like the following (this works when I execute from my Oracle SQL editor):

      SELECT * FROM MyEntity2 t0 WHERE (t0.id, t0.num) IN (SELECT t1.id, t1.num FROM MyEntity2 t1 GROUP BY t1.id, t1.num);

      I.e. we need the parentheses.

      Thanks,

      Heath Thomann

      Attachments

        Activity

          People

            Unassigned Unassigned
            jpaheath Heath Thomann
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: