Spring HibernateTemplate自动提交false

时间:2013-07-13 07:35:57

标签: spring hibernate spring-jdbc

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

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();
}
}

由于

1 个答案:

答案 0 :(得分:-1)

在hibernate中禁用自动提交:

<property name="hibernate.connection.autocommit">false</property> 
相关问题