Reputation: 9745
if you have a namedquery with a list like :
@NamedQuery(name="selection" , query=" SELECT x FROM Employee x WHERE x.name IN ('Jack', 'Jill')")
is it possible to make the list to named bind variables so you set what you want with :
q.setParameter( ....... );
Any suggestions would be welcome
Upvotes: 7
Views: 8271
Reputation: 5506
Use this way
@NamedQuery(name="selection" , query=" SELECT x FROM Employee x WHERE x.name IN (:availableCollection)")
namesCollection // conatains your Lsit of names
query.setParameterList('availableCollection', namesCollection);
Upvotes: 2
Reputation: 692013
Yes, it's possible. Just do it like for any other parameter:
@NamedQuery(name="selection" , query=" SELECT x FROM Employee x WHERE x.name IN :names")
q.setParameter("names", Arrays.asList("Jack", "Jill"));
Upvotes: 11