1

I have an JPQL named query declared this way:

@NamedQuery(name = "Client.findByInternalIds", query =
     "select o from Client o where o.internalId in (:internalIds)")

Here, :internalIds is supposed to be a list i pass as a parameter to the named query on runtime. There problem is whenever i try to do this:

@Override
public List<Client> getClientsByInternalIds(List<Integer> internalIds) {
    TypedQuery<Client> nq = em.createNamedQuery("Client.findByInternalIds", Client.class);
    nq.setParameter("internalIds", internalIds);
    return nq.getResultList();
}

I get basically this error (exception)

java.lang.IllegalArgumentException: You have attempted to set a value of type class java.util.ArrayList for parameter internalIds with expected type of class java.lang.Integer from query string select o from Client o where o.internalId in (:internalIds)

I searched around the internet for a solution, and all seem to say that my syntax is correct, so can anyone help me figure out this please? Thank you.

FYI, using WebLogic 12c, with EclipseLink.

clapsus
  • 442
  • 6
  • 19

1 Answers1

3

I actually wasn't right on the syntax, after many and many tries, the simple solution was to remove the brackets on the internalIds paramter in the @NamedQuery definition.

So the @NamedQuery becomes this:

@NamedQuery(name = "Client.findByInternalIds", query =
     "select o from Client o where o.internalId in :internalIds")

And it works!

clapsus
  • 442
  • 6
  • 19