You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Oliver Gierke (Commented) (JIRA)" <ji...@apache.org> on 2012/02/02 18:08:54 UTC

[jira] [Commented] (OPENJPA-2018) Cannot bind String[] to ParameterExpression for path.in(parameter)

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

Oliver Gierke commented on OPENJPA-2018:
----------------------------------------

It does not seem to work with collections as well:

CriteriaBuilder builder = em.getCriteriaBuilder();

CriteriaQuery<User> criteriaQuery = builder.createQuery(User.class);
Root<User> root = criteriaQuery.from(User.class);
criteriaQuery.where(root.<Integer> get("id").in(builder.parameter(Collection.class)));

TypedQuery<User> query = em.createQuery(criteriaQuery);
for (Parameter parameter : query.getParameters()) {
	query.setParameter(parameter, Arrays.asList(1, 2));
}

List<User> resultList = query.getResultList();

This fails with:

<openjpa-2.0.0-r422266:935683 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: Filter invalid. Cannot compare field id of type java.lang.Integer to value of type java.util.Collection. Numeric comparisons must be between numeric types only. To enable such comparisons for backwards-compatibility, add "QuotedNumbersInQueries=true" to the org.apache.openjpa.Compatibility setting in your configuration.

Tried against 2.0 as well as 2.1. Don't quite get why OpenJPA tries to compare the integer against the collection instead of its values.
                
> Cannot bind String[] to ParameterExpression for path.in(parameter)
> ------------------------------------------------------------------
>
>                 Key: OPENJPA-2018
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2018
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jpa
>    Affects Versions: 2.1.0
>            Reporter: Oliver Gierke
>            Assignee: Michael Dick
>              Labels: binding, criteria_api, jpa
>
> Given the following code:
> {code}
> User user = new User("Dave", "Matthews", "foo@bar.de");
> em.persist(user);
> em.flush();
> CriteriaBuilder builder = em.getCriteriaBuilder();
> CriteriaQuery<User> criteria = builder.createQuery(User.class);
> Root<User> root = criteria.from(User.class);
> criteria.where(root.get("firstname").in(builder.parameter(String[].class)));
> TypedQuery<User> query = em.createQuery(criteria);
> for (ParameterExpression parameter : criteria.getParameters()) {
>   query.setParameter(parameter, new String[] {"Dave", "Carter"});
> }
> List<User> result = query.getResultList();
> assertThat(result.isEmpty(), is(false));
> {code}
> I get a
> {code}
> <openjpa-2.0.0-r422266:935683 nonfatal user error> org.apache.openjpa.persistence.ArgumentException: The specified parameter of type "class [Ljava.lang.String;" is not a valid query parameter.
> {code}
> Using {{Collection}} as {{ParameterExpression}} type and binding the parameters via {{Arrays.asList(...)}} works fine.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira