gpt4 book ai didi

java - hibernate 做预测缓存吗?

转载 作者:搜寻专家 更新时间:2023-10-31 20:22:11 26 4
gpt4 key购买 nike

我们的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com