6

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.

Stefan Steinegger
  • 63,782
  • 15
  • 129
  • 193
Tdev John
  • 61
  • 1
  • 3

3 Answers3

8

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();
Tássio Coêlho
  • 334
  • 3
  • 6
0

What about delete from Table as table where id="value"

In above case

Table- Pojo class

table- Database table name


kark
  • 4,763
  • 6
  • 30
  • 44
0

Use this

Query qry = session.createQuery(delete from Pojo where pojo.property in (:bindParameter);
qry.setParameter("bindParameter", list);

Note this statement SQL exception if list is empty.

Abhijith Nagarajan
  • 3,865
  • 18
  • 23