| Summary: | Criteria In should support arrays as parameters to be bound | ||
|---|---|---|---|
| Product: | z_Archived | Reporter: | Oliver Drotbohm <odrotbohm> |
| Component: | Eclipselink | Assignee: | 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
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. 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. 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.
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink |