6

I have one variable like long[] ids = [10, 11] and I am trying to fire query like this :

Query query2 = session.createQuery("update Employee e SET e.isLatest = false where e.id not in (:ids)");
query2.setParameter("ids", ids);
query2.executeUpdate();

But I am getting error like

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.

How can pass array variable in NOT IN parameter? Or Is there any other way for handling such query ?

1

3 Answers 3

5

Try

query2.setParameterList("ids", ids);
1
  • Thanks Alex, it worked. But before that I converted long[] ids to ArraList<long>. As setParameterList needs collection parameter.
    – Naresh J
    Aug 1, 2013 at 7:04
2

There are two ways

1) use of setParameterList(,); and pass collection

2) Use

query2.setParameter("ids", ids);

where ids is one string , which contains comma separated id

eg.

String commaseperatedId="10,11". and then

query2.setParameter("ids", commaseperatedId);

0

I think query2.setParameters("ids", ids); should work.

OR

Follow Set array of parameters to hibernate query language

query2.setParameterList("ids", ids);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.