Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate 4.1.11 hql delete query with where in list

I want to delete from a table some entries with specific ids. I want to know the syntax of this request

delete from table where id in list_of_ids

in hql.

like image 615
Tdev John Avatar asked Sep 30 '13 09:09

Tdev John


1 Answers

Assuming the id of your table is of type Long, the correct way to perform the delete is as follows:

List<Long> ids = new ArrayList<Long>();
ids.add(1L);
ids.add(2L);

Query q = session.createQuery("DELETE FROM YourEntityName ye WHERE ye.id IN (:list)");

q.setParameterList("list", ids);
q.executeUpdate();
like image 100
Tássio Coêlho Avatar answered Nov 05 '22 19:11

Tássio Coêlho