[hibernate-issues] [Hibernate-JIRA] Created: (HHH-6325) Using Criteria API path.in(...) with ParameterExpression of array fails at binding time

Oliver Gierke (JIRA) noreply at atlassian.com
Wed Jun 15 13:19:25 EDT 2011


Using Criteria API path.in(...) with ParameterExpression of array fails at binding time
---------------------------------------------------------------------------------------

                 Key: HHH-6325
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6325
             Project: Hibernate Core
          Issue Type: Bug
          Components: entity-manager
    Affects Versions: 3.6.5
            Reporter: Oliver Gierke


Given the following test code snippet:

{code}
User user = new User("Dave", "Matthews", "foo at 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}
java.lang.IllegalArgumentException: Parameter value [[Ljava.lang.String;@335ad36d] was not matching type [java.lang.String]
  at org.hibernate.ejb.AbstractQueryImpl.registerParameterBinding(AbstractQueryImpl.java:360)
  at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:364)
  at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:317)
  at org.hibernate.ejb.criteria.CriteriaQueryCompiler$3.setParameter(CriteriaQueryCompiler.java:328)
{code}

If I am using a {{ParameterExpression}} of type {{Collection}} and bind the parameters via {{Arrays.asList(...)}} it works fine. Although it's generally possible to fall back to the collection based binding I'd rather bind the parameter values as is (as I get them handed from somewhere else) without explicit checking and converting.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list