0

我需要从一个表中获取 10 万条记录并以批处理方式插入到另一个表中。我使用 Spring3 hibernate 模板进行插入。我只需要在每 100 条记录后提交,但休眠模板在插入时提交每条记录。如何使用休眠模板执行提交后批量插入或如何在休眠模板中禁用自动提交。

for(everey iteration){
count = count+1;
getHibernateTemplate().setAlwaysNewSession(true);
CurrentPlan plan = new currentplan();
Rate rate = new rate();
plan.setName("aa");
rate.setRate(2);

getHibernateTemplate.saveorUpdate(plan )
getHibernateTemplate.saveorUpdate(rate )
if(count==100){
getHibernateTemplate.flush();
}
}

谢谢

4

1 回答 1

-1

在休眠中禁用自动提交:

<property name="hibernate.connection.autocommit">false</property> 
于 2013-07-13T07:56:56.643 回答