OpenJPA
  1. OpenJPA
  2. OPENJPA-2018

Cannot bind String[] to ParameterExpression for path.in(parameter)

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.0
    • Fix Version/s: 2.3.0
    • Component/s: jpa

      Description

      Given the following 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));
      

      I get a

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

      Using Collection as ParameterExpression type and binding the parameters via Arrays.asList(...) works fine.

      1. OPENJPA-2018-test2.patch
        4 kB
        Mark Struberg
      2. missingpatch.patch
        7 kB
        Romain Manni-Bucau
      3. OPENJPA-2018-with-array.patch
        21 kB
        Romain Manni-Bucau
      4. OPENJPA-2018-test-update.patch
        6 kB
        Romain Manni-Bucau
      5. OPENJPA-2018.patch
        15 kB
        Romain Manni-Bucau
      6. openjpa-2018.zip
        6 kB
        Oliver Gierke

        Activity

        Oliver Gierke created issue -
        Michael Dick made changes -
        Field Original Value New Value
        Assignee Michael Dick [ mikedd ]
        Oliver Gierke made changes -
        Attachment openjpa-2018.zip [ 12609672 ]
        Romain Manni-Bucau made changes -
        Attachment OPENJPA-2018.patch [ 12609811 ]
        Romain Manni-Bucau made changes -
        Attachment OPENJPA-2018-test-update.patch [ 12609921 ]
        Romain Manni-Bucau made changes -
        Attachment OPENJPA-2018-with-array.patch [ 12610323 ]
        Romain Manni-Bucau made changes -
        Attachment missingpatch.patch [ 12610328 ]
        Mark Struberg made changes -
        Attachment OPENJPA-2018-test2.patch [ 12610572 ]
        Mark Struberg made changes -
        Assignee Michael Dick [ mikedd ] Mark Struberg [ struberg ]
        Mark Struberg made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.3.0 [ 12319463 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Mark Struberg
            Reporter:
            Oliver Gierke
          • Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development