开发者

How to set list of values as parameter into hibernate query?

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 c开发者_StackOverflowat.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)


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})
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜