6

次のような変数が1つ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ですか? または、そのようなクエリを処理する他の方法はありますか?

4

3 に答える 3

5

試す

query2.setParameterList("ids", ids);
于 2013-08-01T06:52:39.290 に答える
2

2つの方法があります

1)setParameterList(,);パスコレクションの利用

2) 使用

query2.setParameter("ids", ids);

idsカンマ区切りの ID を含む 1 つの文字列です。

例えば。

String commaseperatedId="10,11". その後

query2.setParameter("ids", commaseperatedId);

于 2013-08-01T07:05:19.823 に答える
0

query2.setParameters("ids", ids); はうまくいくと思います。

また

Set array of parametersに従って、クエリ言語を休止状態にします

query2.setParameterList("ids", ids);
于 2013-08-01T06:59:38.650 に答える