yur*_*ura 25 sql hibernate jpa
例如,我有这个查询
select cat from Cat cat where cat.id in :ids
Run Code Online (Sandbox Code Playgroud)
我想将ID设置为列表(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})
Run Code Online (Sandbox Code Playgroud)
结果我想要像SQL查询一样 id in (1,2,3,4)
sbl*_*ndy 43
使用setParameterList().您还必须在列表参数周围加上括号.
session.createQuery("select cat from Cat cat where cat.id in (:ids)").setParameterList("ids", new Long[]{1,2,3,4,5})
Run Code Online (Sandbox Code Playgroud)