33

For example, I have this query

 select cat from Cat cat where cat.id in :ids 

and I want to set ids to list (1,2,3,4,5,6,17,19).

This code doesn't work

session.createQuery("select cat from Cat cat where cat.id in :ids")
       .setParameter("ids", new Long[]{1,2,3,4,5})

As the result I would like to have SQL query like id in (1,2,3,4)

1 Answer 1

60

Use setParameterList(). You'll also have to put parenthesis around the list param.

session.createQuery("select cat from Cat cat where cat.id in (:ids)").setParameterList("ids", new Long[]{1,2,3,4,5})
Sign up to request clarification or add additional context in comments.

2 Comments

setParameterList is depcreated in newer hibernate. How do we pass this in? I tried using setparameter and didn't get correct behavior...
yes setParameterList is deprecated and i could not get correct behavior too, any update?

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.