7

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

4

2 に答える 2

11

はい、可能です。他のパラメータと同じようにしてください:

@NamedQuery(name="selection" , query=" SELECT x FROM Employee x WHERE x.name IN :names")

q.setParameter("names", Arrays.asList("Jack", "Jill"));
于 2012-12-26T13:52:48.040 に答える
2

このように使う

@NamedQuery(name="selection" , query=" SELECT x FROM Employee x WHERE x.name IN (:availableCollection)") 


namesCollection // conatains your Lsit of names

query.setParameterList('availableCollection', namesCollection);
于 2012-12-26T13:54:43.967 に答える