我正在阅读一篇关于使用休眠进行批量获取的博客http://java.dzone.com/articles/bulk-fetching-hibernate http://java.dzone.com/articles/bulk-fetching-hibernate.
在这之中,ScrollableResults
用作溶液。这里我们仍然需要从会话中驱逐对象。
我不明白如何使用ScrollableResults
(or scroll()
) 与使用不同list()
.
换句话说,以下陈述在性能方面有何不同
List<Employee> empList = session.createCriteria(Employee.class).list();
ScrollableResults sc = session.createCriteria(Employee.class).scroll();
请告诉我。
上面的代码似乎缺少一些设置。
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 http://www.numerati.com/2012/06/26/reading-large-result-sets-with-hibernate-and-mysql/链接以获取更多详细信息和解释。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)