hibernate批量写入

public int insertChanDaoTaskModel(List<T> t) {
// TODO Auto-generated method stub

Session session = this.hibernateTemplate.getSessionFactory().openSession();
Transaction tran = session.beginTransaction();
tran.begin();
try {
for(int i=0;i<t.size();i++){
session.save(t.get(i));
if(i%2000==0){
session.flush();
session.clear();
}
}
tran.commit();
session.close();
return 1;
}
catch (Exception ex) {
// TODO: handle exception
return 0;
}
}

posted @ 2017-11-03 09:37  洞玄巅峰  阅读(213)  评论(0编辑  收藏  举报