Sql 如何将值列表作为参数设置到hibernate查询中?
例如,我有这个查询Sql 如何将值列表作为参数设置到hibernate查询中?,sql,hibernate,jpa,Sql,Hibernate,Jpa,例如,我有这个查询 select cat from Cat cat where cat.id in :ids 我想将ID设置为list(1,2,3,4,5,6,17,19) 这个代码不起作用 session.createQuery("select cat from Cat cat where cat.id in :ids") .setParameter("ids", new Long[]{1,2,3,4,5}) 因此,我希望在(1,2,3,4)中使用类似于id的SQL查询使
select cat from Cat cat where cat.id in :ids
我想将ID设置为list(1,2,3,4,5,6,17,19)
这个代码不起作用
session.createQuery("select cat from Cat cat where cat.id in :ids")
.setParameter("ids", new Long[]{1,2,3,4,5})
因此,我希望在(1,2,3,4)中使用类似于id的SQL查询使用。您还必须在列表参数周围加上括号
session.createQuery("select cat from Cat cat where cat.id in (:ids)").setParameterList("ids", new Long[]{1,2,3,4,5})
setParameterList
是在较新的hibernate中创建的。我们怎么把这个传进来?我尝试使用setparameter
,但没有得到正确的行为。。。