Reputation: 61
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.
Upvotes: 6
Views: 9235
Reputation: 342
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();
Upvotes: 8
Reputation: 4030
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.
Upvotes: 0
Reputation: 4853
What about delete from Table as table where id="value"
In above case
Table- Pojo class
table- Database table name
Upvotes: 0