Hibernate二级缓存ehcache.xml,实体的缓存设置无法读取到HIbernate

发布于 2024-07-23 10:51:10 字数 818 浏览 2 评论 0原文

为了让事情变得简单明了,我有两个项目: 1. 一个实体项目,其中包含该项目中的所有实体类。 2. 一个包含main()函数来运行应用程序的项目,我的ehcache.xml放置在该项目的类路径中。

我的问题是: 我可以更改 ehcache.xml 的 defaultCache 元素,并且可以从 SQL 日志文件中看到更改。 但我认为 Hibernate 只读取我的 defaultCache 元素,因为无论我在 ehcache.xml 的特定实体的 cache 元素中更改什么,都不会发生任何更改SQL 日志。

例如: 如果我将 defaultCache 元素的 maxElementsInMemory 设置为 0,则无论我设置 缓存的 maxElementsInMemory如果实体的 元素达到 1000,则二级缓存中不会缓存任何该实体。 如果我将 defaultCache 元素的 maxElementsInMemory 设置为 100,无论我设置 缓存的 maxElementsInMemory实体的 元素到 1000 时,总会有该实体缓存在二级缓存中。

所以我想也许实体的 cache 元素的 name 属性设置错误并且无法从 Hibernate 读取?

To make it clear and easy, I have two projects:
1. An Entity project where there are all the entity classes in this project.
2. An project that contains a main() function to run the application, My ehcache.xml is placed in the class path of this project.

My problem is:
I can change the defaultCache element of ehcache.xml and I can see changes from the SQL log file. But I think the Hibernate only read my defaultCache element, because whatever I change in the cache element of a specific entity of ehcache.xml, there won't be any changes in the SQL log.

For example:
If I set the maxElementsInMemory of defaultCache element to 0, whatever I set the maxElementsInMemory of the cache element of a entity to 100 or 0, there won't be any that entity cached in the second level cache. If I set the maxElementsInMemory of defaultCache element to 100, whatever I set the maxElementsInMemory of the cache element of a entity to 100 or 0, there are always be that entity cached in the second level cache.

So I think maybe the name attribute of the cache element of a entity is wrongly set and cannot be read from Hibernate?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一场春暖 2024-07-30 10:51:10

我发现我的问题出在哪里了。 我使用 ehcache 作为缓存提供程序。 在 ehcache.xml 中,如果我没有设置 standardQueryCache 元素,我认为 defaultCache 元素也用于所有 QueryCache。 因此,是否将 maxElementsInMemory 设置为“0”并不重要,因为所有 QueryCache 都使用 defaultCache 区域。 但是,在使用 EntityManager.find() 函数时,将 maxElementsInMemory 设置为“0”肯定有助于禁用该实体的第二级缓存。

I found where my problem is. I'm using ehcache as cache provider. In the ehcache.xml,I think the defaultCache element is also used for ALL THE QueryCaches too, if I didn't set the standardQueryCache element. So it's not important whether or not I set the maxElementsInMemory of to "0", because all the QueryCache are using the defaultCache region. But setting the maxElementsInMemory of to "0" can definitely help to disable the sencond-level cache of that entity when using EntityManager.find() function.

演多会厌 2024-07-30 10:51:10

请阅读文档。 在 maxElementsInMemory 设置的情况下,值 0 具有特殊含义 - 无限制。 因此,您不是完全没有缓存,而是缓存所有内容。

PLEASE, read the documentation. In case of maxElementsInMemory setting, a value of 0 has a special meaning - unlimited. So instead of getting no cache at all, you're caching everything.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文