I need to delete entries from a table based on a key, and these entries might come to around 5 million. There are two ways to go about it. One using Hibernate and the other by direct SQL query.
Hibernate:
List<Employee> empList =
getHibernateTemplate()
.findByNamedParam("from Employee emp where emp.Id=:empId","empId",employeeId);
Iterator<Employee> empIter = empList .iterator();
while(empIter.hasNext()) {
Employee empTran = empIter.next();
getHibernateTemplate().delete("Employee", empTran);
SQL:
delete from Employee where Id = employeeId";
Which among the two will get the results faster? And can the Hibernate query be tuned further?
(Please ignore syntax errors if any)