java - hibernate 做预测缓存吗?

标签 java hibernate sql-server-2008-r2

我们的 DBA 刚刚回来,对我们的 SQL 服务器数据库进行了长时间运行的查询。他认为我们应该审查该查询,看看我们是否可以优化。

问题是查询不是来 self 们的应用程序代码。它通过主键从单个表中加载大量记录,准确地说是九个,而且我们从来没有通过我们的应用程序通过主键对该表进行任何查询。通过 hibernate 执行的名称修改和所有属性的加载,它也绝对是一个 hibernate 查询。

所以我想知道 hibernate 是否会进行一些预测性缓存,比如提取它认为我稍后可能需要的记录。对此有任何意见吗?

谢谢。

最佳答案

这可能是由于 batch fetching 而执行的查询:

Using batch fetching, Hibernate can load several uninitialized proxies if one proxy is accessed. Batch fetching is an optimization of the lazy select fetching strategy.

Batch fetching for classes/entities is easier to understand. Consider the following example: at runtime you have 25 Cat instances loaded in a Session, and each Cat has a reference to its owner, a Person. The Person class is mapped with a proxy, lazy="true". If you now iterate through all cats and call getOwner() on each, Hibernate will, by default, execute 25 SELECT statements to retrieve the proxied owners. You can tune this behavior by specifying a batch-size in the mapping of Person:

<class name="Person" batch-size="10">...</class>

Hibernate will now execute only three queries: the pattern is 10, 10, 5.

关于java - hibernate 做预测缓存吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11528827/

相关文章:

java - 出现严重错误 : MessageBodyWriter not found for media type=application/xml,

java - 如何根据特定顺序对 hibernate 结果进行排序

sql - 如何对引用 SQL 中其他几个实体之一的一个实体进行建模?

ssis - SSIS 脚本组件上的 WATIN - 单线程单元

sql-server-2008-r2 - 检查 SQL SERVER 中的列是否为 NULL

java - 如何从 Thymeleaf 模板访问库 JAR 文件中的样式表?

java - junit 中的 @Transactional 注解 - spring 和 jms

java - 使用 @OneToMany 注释关系时是否可以定义 LEFT Join?

java - 测试 spring hibernate dao 和服务层

java - 将基于 Java OpenGL 的 Android 游戏移植到 iOS(无 native 代码)