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

2 Answers 2

11

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"));
Sign up to request clarification or add additional context in comments.

1 Comment

Parenthesis not required? Other answer includes them – Found some details over at this answer
2

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.