In the following JPA query, the :fcIds named parameter needs to be a list of integer values:
@NamedQuery(name = "SortTypeNWD.findByFcIds", query = "SELECT s FROM SortTypeNWD s WHERE s.sortTypeNWDPK.fcId IN (:fcIds)")
Quite logically, this is what is done when the named query is called:
Query findByDatesPlFcIds = em.createNamedQuery("SortTypeNWD.findByFcIds");
findByDatesPlFcIds.setParameter("fcIds", fcIds);
Where the variable fcIds is an ArrayList containing integers.
All the above code works fine with Hibernate but doesn't with TopLink:
Caused by: java.lang.IllegalArgumentException: You have attempted to set a value of type class java.util.ArrayList for parameter fcIds with expected type of int from query string SELECT s FROM SortTypeNWD s WHERE s.sortTypeNWDPK.fcId IN (:fcIds).
Is there a workaround to use a List as a named parameter in TopLink? Can the type of the named parameter be forced?
Toplink implements JPA 1.0 which doesn't support passing a list as a parameter (collection_valued_input_parameter is the term used in documentation). This is supported in JPA 2.0 which is implemented in TopLink's successor, EclipseLink.
If you have to stick with TopLink then you need to write a loop to include each item on the list as a parameter.