注册 登录
编程论坛 J2EE论坛

[求助]Mysql在Hibernate中,如何使用批量提交?

limaoyuan 发布于 2007-07-31 13:07, 1106 次点击
Mysql在Hibernate中,如何使用批量提交?

PS:

以下的配置在MYSQL中无效。。。

hibernate.jdbc.batch_size 20


Test.java

Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
for ( int i=0; i<100000; i++ ) {
Customer customer = new Customer(.....);
session.save(customer);
if ( i % 20 == 0 ) { //20, same as the JDBC batch size
//flush a batch of inserts and release memory:
session.flush();
session.clear();
}
}
tx.commit();
session.close();


-----------------------------


谢谢!
2 回复
#2
Gramary2007-07-31 13:32
我以前也试过这样插入数据
连续插入了几百条后就会内存益出``
我很郁闷 一直没找到解决的方法``` 、
希望高手来帮忙指点一下``
#3
limaoyuan2007-07-31 14:36

居说这种batch提交对MYSQL无效。。。应该是有另外的一种针对MYSQL批量提交的解决办法 。。。。


我实在是想不起来了。。。请知情者,告知一下。。多谢~~

1