[ 
https://issues.apache.org/jira/browse/OPENJPA-2688?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15903070#comment-15903070
 ] 

Mark Struberg commented on OPENJPA-2688:
----------------------------------------

the native SQL "select * from Bla where name in ()" blows up with an error. 
This is not an allowed SQL syntax at least.
The question is what an empty IN statement means in JPA. 
Is it defined at all? How should it behave? 
* illegal -> blow up. In that case it should fail for _both_ cases imo!
* allowed, but treated as 'no match'? -> always result in an empty result
* allowed, but treated as 'ignore parameter'? -> ignore parameter ;)

Any ideas?

> 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)

Reply via email to