Consider the below two methods to delete a Set of Employees with the name "John" .
List<Employee> list = new ArrayList<Employee>();
String query= " from Employee emp where emp.name = 'John'";
Iterator<BulkChangeRequest> itList = list.iterator();
Employee emp = itList.next();
" delete from Employee where name = 'John'"
Yes. It would be better to use SQL or HQL to delete all employee records named 'John' rather then the first option. Simply because in first option, you have to load all employee record from db to delete. That's obviously an extra task.
I think, for
deleteAll(), there will be no difference except in
delete(), it will create new session for every call; whereas in
deleteAll(), all objects will be deleted in one session. But the number of queries will be the same.