使用可滚动结果集批量读取hibernate中的数据 [英] Bulk reading of data in hibernate using scrollable result set

查看:347
本文介绍了使用可滚动结果集批量读取hibernate中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用hibernate http://java.dzone阅读有关批量抓取的博客。 com / articles / bulk-fetching-hibernate
在此,使用 ScrollableResults 作为解决方案。这里仍然需要从会话中驱逐对象。

我不明白如何使用 ScrollableResults (或 scroll())与使用 list()不同。

换句话说,下面的表现如何在表现方面有所不同


 列表<员工> empList = session.createCriteria(Employee.class).list(); 
ScrollableResults sc = session.createCriteria(Employee.class).scroll();

请让我知道。

 查询查询= session.createQuery()解决方案

上述代码似乎缺少一些设置。查询);
query.setReadOnly(true);
// MIN_VALUE给予JDBC驱动程序以流结果的提示
query.setFetchSize(Integer.MIN_VALUE);
ScrollableResults results = query.scroll(ScrollMode.FORWARD_ONLY);
//遍历结果
while(results.next()){
Object row = results.get();
//处理行然后释放引用
//你可能需要flush()以及
}
results.close();

关注这个链接以获得更多细节和解释。


I was reading a blog regarding bulk fetching with hibernate http://java.dzone.com/articles/bulk-fetching-hibernate.
In this, ScrollableResults is used as a solution. Here still we need to evict objects from session.
I don't understand how using ScrollableResults(or scroll()) is different from using list().

In other words, how the below statements differ in terms of performance

 List<Employee> empList = session.createCriteria(Employee.class).list();
 ScrollableResults sc = session.createCriteria(Employee.class).scroll();

Please let me know.

解决方案

The above code seems to be missing some settings.

Query query = session.createQuery(query);
query.setReadOnly(true);
// MIN_VALUE gives hint to JDBC driver to stream results
query.setFetchSize(Integer.MIN_VALUE);
ScrollableResults results = query.scroll(ScrollMode.FORWARD_ONLY);
// iterate over results
while (results.next()) {
    Object row = results.get();
    // process row then release reference
    // you may need to flush() as well
}
results.close();

Follow this link for more details and explanation.

这篇关于使用可滚动结果集批量读取hibernate中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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