快速获得冬眠结果的方法?

编程入门 行业动态 更新时间:2024-10-12 01:28:40
本文介绍了快速获得冬眠结果的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我目前在我的项目中设置了hibernate。它适用于大多数事情。但是今天我需要查询从表中返回几十万行。它是表中总行数的2/3。问题是查询需要7分钟。使用直接JDBC并执行我认为是相同的查询,它需要< 20秒。因此,我认为我正在做一些完全错误的事情。我将在下面列出一些代码。

DetachedCriteria criteria = DetachedCriteria.forlass(MyObject.class); criteria.add(Restrictions.eq(booleanFlag,false)); 列表< MyObject> list = getHibernateTemplate()。findByCriteria(criteria);

关于为什么它会变慢和/或我能做些什么来改变它?您可能已经回答了您自己的问题,请使用直接的JDBC。

$ b $

解决方案 b Hibernate为每行创建一个 Object 的实例,或者更糟的是,多个 Object 每个行的实例。 Hibernate有一些真正退化的代码生成和实例化行为,难以控制,特别是对于大型数据集,如果启用了任何缓存选项,甚至会更糟。

Hibernate不适合大型结果集,并且处理成千上万行作为对象的行也不是很注重性能。

原始JDBC只是行列的原始类型。数据量少的订单。

I currently have hibernate set up in my project. It works well for most things. However today I needed to have a query return a couple hundred thousand rows from a table. It was ~2/3s of the total rows in the table. The problem is the query is taking ~7 minutes. Using straight JDBC and executing what I assumed was an identical query, it takes < 20 seconds. Because of this I assume I am doing something completely wrong. I'll list some code below.

DetachedCriteria criteria =DetachedCriteria.forlass(MyObject.class); criteria.add(Restrictions.eq("booleanFlag", false)); List<MyObject> list = getHibernateTemplate().findByCriteria(criteria);

Any ideas on why it would be slow and/or what I could do to change it?

解决方案

You have probably answered your own question already, use straight JDBC.

Hibernate is creating at best an instance of some Object for every row, or worse, multiple Object instances for each row. Hibernate has some really degenerate code generation and instantiation behavior that can be difficult to control, especially with large data sets, and even worse if you have any of the caching options enabled.

Hibernate is not suited for large results sets, and processing hundreds of thousands of rows as objects isn't very performance oriented either.

Raw JDBC is just that raw types for rows columns. Orders of magnitudes of less data.

更多推荐

快速获得冬眠结果的方法?

本文发布于:2023-11-30 13:51:17,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:快速   方法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!