【发布时间】:2013-07-13 07:35:56
【问题描述】:
我需要从一个表中获取 10 万条记录并以批处理方式插入到另一个表中。我正在使用 Spring3 hibernate 模板进行插入。我只需要在每 100 条记录后提交,但 hibernate 模板在插入时提交每条记录.如何使用hibernate模板进行提交后批量插入或如何在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();
}
}
谢谢
【问题讨论】:
-
HibernateTemplate 不会在每次插入后提交。它根本不承诺。向我们展示您的代码。
-
你读过
setAlwaysUseNewSession()的javadoc吗?如果是这样,你为什么将它设置为 true,因为它正是你不想做的事情?
标签: spring hibernate spring-jdbc