OpenJPA
  1. OpenJPA
  2. OPENJPA-1828

Query with expression IN (collection_valued_input_parameter) should report syntax error, correct usange is IN collection_valued_input_parameter

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.0
    • Fix Version/s: 2.1.0
    • Component/s: None
    • Labels:
      None
    • Environment:
      openjpa-2.1.0-20101001.064809-70

      Description

      for (int i = 0; i < 2; i ++)

      { List categories = new LinkedList(); categories.add("01"); categories.add("02"); categories.add("03"); Query q = entityManager.createQuery("select v.id from Category v where v.id in (:p) order by v.id asc"); q.setParameter("p", categories); List results = q.getResultList(); for (Iterator it = results.iterator(); it.hasNext(); ) System.out.print(it.next() + ", "); System.out.println(); }

      The above code will produce the following output:
      01, 02, 03,
      02, 03,

      "01" is missing when the second time the same query is executed.

        Activity

        Hide
        Michael Dick added a comment -

        Closing issue which has been resolved for some time. If you believe the issue is not resolved please reopen or open a new issue.

        Show
        Michael Dick added a comment - Closing issue which has been resolved for some time. If you believe the issue is not resolved please reopen or open a new issue.
        Hide
        Azuo Lee added a comment -

        Thanks, eliminating the enclosing parentheses solves the problem.

        Show
        Azuo Lee added a comment - Thanks, eliminating the enclosing parentheses solves the problem.
        Hide
        Catalina Wei added a comment -

        1. JPA2 Spec defines the collectioin_valued_paramater usage in IN expression is:
        in_expression ::=

        {state_field_path_expression | type_discriminator}

        [NOT] IN
        { ( in_item

        {, in_item}

        * ) | (subquery) | collection_valued_input_parameter }

        Notice that the collection_valued_input_parameter is not enclosed in parentheses.

        If the input parameter is changed from "()" to "" in the query string as below, then the correct output is produced :

        "select v.id from Category v where v.id in order by v.id asc"

        2. Single_valued_input_parameter vs. Collection_valued_input_parameter validation was missing, which caused incorrect result
        when the second time the same query is executed.
        The fix is to validate it at runtime.
        The committed code will report ArgumentException if a single_valued_parameter is specified, but user is passing a collection value.

        Show
        Catalina Wei added a comment - 1. JPA2 Spec defines the collectioin_valued_paramater usage in IN expression is: in_expression ::= {state_field_path_expression | type_discriminator} [NOT] IN { ( in_item {, in_item} * ) | (subquery) | collection_valued_input_parameter } Notice that the collection_valued_input_parameter is not enclosed in parentheses. If the input parameter is changed from "( )" to " " in the query string as below, then the correct output is produced : "select v.id from Category v where v.id in order by v.id asc" 2. Single_valued_input_parameter vs. Collection_valued_input_parameter validation was missing, which caused incorrect result when the second time the same query is executed. The fix is to validate it at runtime. The committed code will report ArgumentException if a single_valued_parameter is specified, but user is passing a collection value.

          People

          • Assignee:
            Catalina Wei
            Reporter:
            Azuo Lee
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development