/**
* 批量插入
* @param answers
*/
public boolean batchSave(List<SurAnswers> answers){
System.out.println("批量插入数据条数:"+answers.size());
boolean flag = false;
Transaction tx = null;
try {
tx = getSession().beginTransaction();
int i =0;
for(SurAnswers as:answers){
i++;
getSession().save(as);
if(i%10==0){
getSession().flush();
getSession().clear();
tx.commit();
tx = getSession().beginTransaction();
}
}
tx.commit();
flag = true;
} catch (Exception e) {
e.printStackTrace();
flag = false;
}finally{
closeSession();
}
return flag;
}
/**
Hibernate批量插入
最新推荐文章于 2021-05-15 16:43:13 发布