OpenJPA
  1. OpenJPA
  2. OPENJPA-573

JPQL: The combination LIKE ESCAPE does not accept parameters

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0.2, 1.1.0
    • Fix Version/s: 1.0.4, 1.1.0, 1.2.0
    • Component/s: None
    • Labels:
      None
    • Environment:
      SUN JDK 1.6.0.6 (AMD64) for Linux

      Description

      If i use constants like this :

      SELECT object FROM MyObject object WHERE object.path LIKE '%|_%' ESCAPE '|'

      all is ok, but if I want to use parameters - exception is thrown.

      Example:

      @Entity
      @Table(name="simple_object")
      public class MySimpleObject {

      @Id
      String Id ;

      @Basic
      @Column(name="value", nullable=false, length=36)
      String value ;
      .....................
      .......................

      EntityManager em = emf.createEntityManager() ;
      Query q = em.createQuery("SELECT x FROM MySimpleObject x WHERE x.value LIKE ?1 ESCAPE '|'") ;
      q.setParameter(1, "%|_%") ;
      List<MySimpleObject> res = q.getResultList() ;

      Exception in thread "main" <openjpa-1.1.0-SNAPSHOT-r422266:648359 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: Encountered "ESCAPE" at character 54, but expected: ["AND", "GROUP", "HAVING", "OR", "ORDER", <EOF>].
      at org.apache.openjpa.kernel.jpql.JPQL.generateParseException(JPQL.java:9499)
      at org.apache.openjpa.kernel.jpql.JPQL.jj_consume_token(JPQL.java:9376)
      at org.apache.openjpa.kernel.jpql.JPQL.parseQuery(JPQL.java:75)
      at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder$ParsedJPQL.parse(JPQLExpressionBuilder.java:1733)
      at org.apache.openjpa.kernel.jpql.JPQLExpressionBuilder$ParsedJPQL.<init>(JPQLExpressionBuilder.java:1720)
      at org.apache.openjpa.kernel.jpql.JPQLParser.parse(JPQLParser.java:48)
      at org.apache.openjpa.kernel.ExpressionStoreQuery.newCompilation(ExpressionStoreQuery.java:149)
      at org.apache.openjpa.datacache.QueryCacheStoreQuery.newCompilation(QueryCacheStoreQuery.java:239)
      at org.apache.openjpa.kernel.QueryImpl.newCompilation(QueryImpl.java:656)
      at org.apache.openjpa.kernel.QueryImpl.compilationFromCache(QueryImpl.java:638)
      at org.apache.openjpa.kernel.QueryImpl.compileForCompilation(QueryImpl.java:604)
      at org.apache.openjpa.kernel.QueryImpl.compileForExecutor(QueryImpl.java:666)
      at org.apache.openjpa.kernel.QueryImpl.getOperation(QueryImpl.java:1486)
      at org.apache.openjpa.kernel.DelegatingQuery.getOperation(DelegatingQuery.java:123)
      at org.apache.openjpa.persistence.QueryImpl.execute(QueryImpl.java:227)
      at org.apache.openjpa.persistence.QueryImpl.getResultList(QueryImpl.java:277)
      at Tester.testEscape(Tester.java:75)
      at Tester.main(Tester.java:93)

        Activity

        Hide
        Catalina Wei added a comment -

        An easy fix is on this line (line# 1253) in JPQL.jjt:
        input_parameter() | string_literal()

        changed the above line to add parenthesis around it as the following,
        (input_parameter() | string_literal())

        Catalina

        Show
        Catalina Wei added a comment - An easy fix is on this line (line# 1253) in JPQL.jjt: input_parameter() | string_literal() changed the above line to add parenthesis around it as the following, (input_parameter() | string_literal()) Catalina
        Hide
        Georgi Naplatanov added a comment -

        Thank you, Catalina.

        This patch works for me.
        In case i want to set parameter for ESCAPE function what i should to change in JPQL.jjt ?
        I suppose that something should be changed in the following lines:

        void escape_character() #ESCAPECHARACTER :

        { Token t; }

        {
        t = <STRING_LITERAL>

        { jjtThis.setToken (t); }

        }

        ?

        Thank you very much.

        Show
        Georgi Naplatanov added a comment - Thank you, Catalina. This patch works for me. In case i want to set parameter for ESCAPE function what i should to change in JPQL.jjt ? I suppose that something should be changed in the following lines: void escape_character() #ESCAPECHARACTER : { Token t; } { t = <STRING_LITERAL> { jjtThis.setToken (t); } } ? Thank you very much.
        Hide
        Catalina Wei added a comment -

        Fixed under Revision: 653176

        Show
        Catalina Wei added a comment - Fixed under Revision: 653176
        Hide
        Michael Dick added a comment -

        Reopening to merge to 1.0.x

        Show
        Michael Dick added a comment - Reopening to merge to 1.0.x

          People

          • Assignee:
            Michael Dick
            Reporter:
            Georgi Naplatanov
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development