Hibernate3.0取消了以往的session.delete(sql)的批量删除方法(原版被取消的方法可以在org.hibernate.classic包内找到原版的Session类)
那么,hibernate3.0实现批量方式的方法为:
public void cleanCMHistory(Date date) {
Session session = getSession();
Transaction tx = session.beginTransaction();
try {
String hqlDelete = "delete CMInfo where timeStamp < :cleanTime";
int deletedEntities = session.createQuery(hqlDelete).setTimestamp(
"cleanTime", date).executeUpdate();
//先查询出符合条件的结果集,再将其置空
//此事例删除where子句判定列为timestamp类型,故使用setTimestamp,其他
//类型应调用相应的set方法
tx.commit();
}
catch (Exception ex) {
log.info(ex);
tx.rollback();
}
session.close();
}