[jira] [Created] (OPENJPA-2688) JPQL "IN (:collection)" vs "IN :collection"

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Created] (OPENJPA-2688) JPQL "IN (:collection)" vs "IN :collection"

JIRA jira@apache.org
Alexander Falb created OPENJPA-2688:
---------------------------------------

             Summary: JPQL "IN (:collection)" vs "IN :collection"
                 Key: OPENJPA-2688
                 URL: https://issues.apache.org/jira/browse/OPENJPA-2688
             Project: OpenJPA
          Issue Type: Bug
    Affects Versions: 2.4.2, 3.0.0
            Reporter: Alexander Falb


Both of the following JPQL queries work in OpenJPA, as long as there is at least one element in the collection
{code}
SELECT a FROM EntityA a WHERE a.val IN (:collection)
SELECT a FROM EntityA a WHERE a.val IN :collection
{code}
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
{code}org.apache.openjpa.jdbc.kernel.exps.InExpression#getCollection(ExpContext ctx, ExpState state){code}
which handles the first syntax and
{code}org.apache.openjpa.jdbc.kernel.exps.CollectionParam#calculateValue(Select sel, ExpContext ctx, ExpState state, Val other, ExpState otherState){code}
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:
{code}
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
{code}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)