Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing parameter to HQL

Tags:

hibernate

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 ?

like image 594
Naresh J Avatar asked Aug 01 '13 06:08

Naresh J


2 Answers

Try

query2.setParameterList("ids", ids);
like image 200
Alex Avatar answered Sep 29 '22 09:09

Alex


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);

like image 33
swapy Avatar answered Sep 29 '22 07:09

swapy