我有一个像long[] ids = [10, 11]
这样的变量,我试图像这样触发查询:
Query query2 = session.createQuery("update Employee e SET e.isLatest = false where e.id not in (:ids)");
query2.setParameter("ids", ids);
query2.executeUpdate();
但是我收到了像
这样的错误org.postgresql.util.PSQLException: ERROR: operator does not exist: bigint <> character varying
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
如何在NOT IN
参数中传递数组变量?或者还有其他方法来处理这样的查询吗?
答案 0 :(得分:5)
尝试
query2.setParameterList("ids", ids);
答案 1 :(得分:2)
有两种方式
1)使用setParameterList(,);
并传递集合
2)使用
query2.setParameter("ids", ids);
其中ids
是一个字符串,其中包含以逗号分隔的ID
例如。
String commaseperatedId="10,11".
然后
query2.setParameter("ids", commaseperatedId);
答案 2 :(得分:0)
我认为query2.setParameters("ids", ids);
should work。
关注Set array of parameters to hibernate query language
query2.setParameterList("ids", ids);