如何将值列表作为参数设置为hibernate查询? [英] How to set list of values as parameter into hibernate query?
本文介绍了如何将值列表作为参数设置为hibernate查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,我有这个查询
从猫猫中选择猫,其中cat.id在:ids
我想将id设置为列表(1,2,3,4,5,6,17,19) 。
此代码无效
session.createQuery( cat cat from cat from cat)
.setParameter(ids,new Long [] {1,2,3,4,5})
$ p $结果我想在(1,2,3,4)中有id这样的SQL查询 解决方案session.createQuery(从猫猫那里选择猫。 id in(:ids))。setParameterList(ids,new Long [] {1,2,3,4,5})
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)
解决方案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})
这篇关于如何将值列表作为参数设置为hibernate查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文