在hibernate中插入大量记录的最佳方法 [英] Best way to insert a good amount of records in hibernate

查看:102
本文介绍了在hibernate中插入大量记录的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用hibernate + play!在工作框架,是否有一个最佳做法插入大量的记录使用休眠?他们每个文本文件大约有6,000到10,000个,所以我不知道Hibernate是否会在工作中窒息或抛出异常。



任何建议都让我知道,让我知道如果我必须解释更多

从Java Persistence和Hibernate(Manning) ,使用无状态会话(没有持久化上下文缓存):

pre $ StatelessSession session = sessionFactory.openStatelessSession();
Transaction tx = session.beginTransaction();
for(int i = 0; i <100000; i ++){
Item item = new Item(...);
session.insert(item);
}
tx.commit();
session.close();


I'm using hibernate + play! framework at work, is there a "best practice" on inserting a good amount of records using hibernate? They are around 6,000 to 10,000 per text file so I don't know if Hibernate is going to choke on the job or throw an exception.

Any suggestion let me know, let me know if I have to explain more

解决方案

From *Java Persistence and Hibernate" (Manning) and following a comment from Pangea, use a stateless session (which doesn't have a persistence context cache) :

StatelessSession session = sessionFactory.openStatelessSession();
Transaction tx = session.beginTransaction();
for ( int i=0; i<100000; i++ ) {
    Item item = new Item(...);
    session.insert(item);
}
tx.commit();
session.close();

这篇关于在hibernate中插入大量记录的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆