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

JPQL "IN (:collection)" vs "IN :collection"

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.4.2, 3.0.0
    • None
    • None
    • None

    Description

      Both of the following JPQL queries work in OpenJPA, as long as there is at least one element in the collection

      SELECT a FROM EntityA a WHERE a.val IN (:collection)
      SELECT a FROM EntityA a WHERE a.val IN :collection
      

      When the collection is empty, only the first query works, the second one throws an IllegalArgumentException("empty-collection-parm").

      The problem seems to be in the difference between

      org.apache.openjpa.jdbc.kernel.exps.InExpression#getCollection(ExpContext ctx, ExpState state)

      which handles the first syntax and

      org.apache.openjpa.jdbc.kernel.exps.CollectionParam#calculateValue(Select sel, ExpContext ctx, ExpState state, Val other, ExpState otherState)

      for the second syntax.

      InExpression just collects all parameters between the parenthesis in a collection, where as CollectionParam does a few sanity checks first and throws aforementioned exception.

      In my opinion the behaviour should be the same OR the first syntax should not be allowed altogether, because it violates the JPQL definition for IN expressions:

      in_expression ::=
              {state_valued_path_expression | type_discriminator} [NOT] IN
                      { ( in_item {, in_item}* ) | (subquery) | collection_valued_input_parameter }
      in_item ::= literal | single_valued_input_parameter
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            elexx Alexander Falb
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: