批量保存,批量插入数据
/*** 批量保存
*/
public boolean save(List<T> list) {
Session session = HibernateUtils.getSession();
Transaction transaction = session.beginTransaction();
try { www.zzzyk.com
for (int i = 0; i < list.size(); i++) {
session.save(list.get(i));
if (i % 2000 == 0 || i == list.size() - 1) {
session.flush();
transaction.commit();
}
}
} catch (HibernateException e) {
e.printStackTrace();
transaction.rollback();
return false;
} finally {
HibernateUtils.closeSession(session);
}
return true;
}
补充:综合编程 , 其他综合 ,