Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 349728

Summary: Criteria In should support arrays as parameters to be bound
Product: z_Archived Reporter: Oliver Drotbohm <odrotbohm>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P2 CC: dazeydev.3, jens, omidatbiz, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=349477
Whiteboard:

Description Oliver Drotbohm CLA 2011-06-17 15:53:01 EDT
Build Identifier: 

Currently when handing in an array of objects on parameter binding for an In-clause EclipseLink doesn't seem to bind the values individually but rather the array itself.

Reproducible: Always
Comment 1 Tom Ware CLA 2011-06-30 15:13:30 EDT
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines

Community: Please vote for this bug if it is important to you.  Votes are one of the main criteria we use to determine which bugs to fix next.
Comment 2 Omid Pourhadi CLA 2018-11-20 04:17:04 EST
I voted and I will be waiting another 4 years just like this https://bugs.eclipse.org/bugs/show_bug.cgi?id=349477 to be solved.
Comment 3 Will Dazey CLA 2020-09-14 14:50:44 EDT
Not quite sure if this IS a bug or just a limitation of the JPA spec.

Based on the JPA Criteria API for `javax.persistence.criteria.Expression`, we only have the following methods (seems only the 1st and 3rd are applicable here):
```
/**
* Create a predicate to test whether the expression is a member
* of the argument list.
* @param values values to be tested against
* @return predicate testing for membership
*/
Predicate in(Object... values);

Predicate in(Expression<?>... values);

/**
* Create a predicate to test whether the expression is a member
* of the collection.
* @param values collection of values to be tested against
* @return predicate testing for membership
*/
Predicate in(Collection<?> values);

Predicate in(Expression<Collection<?>> values);
```

What the submitter of this bug seems to be looking for is the behavior of the 3rd method, but passing an Object[] instead of a `java.util.Collection`. The problem is that Object[] is NOT an instance of `java.util.Collection`. 
This means that passing an Object[] HAS to apply to API method #1. But that method doesn't make special considerations for Object[]s.

Consider the following example:

Example #1:
```
    final CriteriaBuilder builder = em.getCriteriaBuilder();
    final CriteriaQuery<Foo> query = builder.createQuery(Foo.class);
    Root<L1> root = query.from(Foo.class);

    query.where(root.get("name").in(new Object[] {"A", "B", "C", "D"}));
```
Based on this example, you may expect a query like this:
```
SELECT ID, NAME FROM FOO WHERE (NAME IN (?, ?, ?, ?))
	bind => [A, B, C, D]
```

But your not using the API `javax.persistence.criteria.Expression.in(Collection<?> arg0)`. Instead, your calling `javax.persistence.criteria.Expression.in(Object... arg0)` where the only argument is an entire Object[]. How can EclipseLink make a special consideration in this case? The specification does not describe a special behavior for Object[]s and adding it may change the behavior of other use cases.

I think the best fix for this case would be to add a new API call to `javax.persistence.criteria.Expression`:
```
/**
* Create a predicate to test whether the expression is a member
* of the array.
* @param values array of values to be tested against
* @return predicate testing for membership
*/
Predicate in(Object[] values)
```
Then, EclipseLink can implement that API. Until then, I think this bug/enhancement cannot be implemented.
Comment 4 Eclipse Webmaster CLA 2022-06-09 10:20:15 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink