Passing a parameter in HQL

I have one variable of type long[] ids = [10, 11] , and I'm trying to run a 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 get an 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 to pass array variable to NOT IN parameter? Or is there any other way to handle such a request?

+6
source share
3 answers

Try

 query2.setParameterList("ids", ids); 
+5
source

There are two ways:

1) using setParameterList(,); and transfer the collection

2) Use

 query2.setParameter("ids", ids); 

where ids is one line that contains a comma separated id

eg.

String commaseperatedId="10,11". and then

query2.setParameter("ids", commaseperatedId);

+2
source

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

OR

Follow Set up an array of parameters for the sleeping query language

 query2.setParameterList("ids", ids); 
0
source

Source: https://habr.com/ru/post/950789/


All Articles