thank you! much relieved that I didn't have to do anything drastic! this
is much better :)
Pinaki Poddar wrote:
Hi,
This use case is better served by IN expression. There is no need to
expand the elements of parameter collection and append them dynamically. The
MEMBER OF expression accepts a collection valued path expression and can not
be parametrized by a collection.
The following works:
String jpql = "select p from Person p where p.nickname in (:coll)";
Collection param = Arrays.asList(new String[]{"a","b","c"});
em.createQuery(jpql)
.setParameter("coll", param)
.getResultList();
will return Person instances whose nickname happens to be either "a","b"
or "c".
Few notes:
1. Notice the parentheses around :coll
2. p.name of course be type compatible with elements of collection
parameter.
3. Following parameter settings are incorrect:
String param = "a,b,c";
or
String[] param = new String[]{"a","b","c"};