具有一个 Hibernate 映射的多个二级缓存设置
假设有多个 Java 应用程序共享一个公共实体模块(实体类 + Hibernate XML 映射)。目前,实体未启用缓存(映射中没有
元素)。
大多数应用程序很大程度上关注编辑单个实体,因此它不能依赖二级缓存。
现在,实现了一个新应用程序,它
- 应该使用相同的实体映射
- ,但必须使用二级缓存和查询缓存。
如何配置缓存?
几个观察结果:
我无法将
元素添加到映射中,因为这会破坏其他应用程序不要配置这样的缓存并且不受我的影响:二级缓存未启用[hibernate.cache.use_second_level_cache | hibernate.cache.use_query_cache]
- 我找不到激活实体以在其映射之外进行缓存的方法。
ehcache.xml
中,为实体设置缓存区域也无济于事 - 即使我可以更改所有其他应用程序并将
添加到 实体映射,通过设置 hibernate.cache.use_second_level_cache=false 来禁用缓存是行不通的,尽管在 http://docs.jboss.org/hibernate/core /3.3/reference/en/html/session-configuration.html,表3.5
Supose that there multiple Java applications which share a common entity module (Entity classes + Hibernate XML mappings). Currently, the entities are not enabled for caching (no <cache.../>
elements within the mappings).
Most of the applications are largly concerned with editing single entities an thus it cannot relie on second level cache.
Now, a new application is implemented which
- Should use the same entity mappings
- but must use 2nd level and query cache.
How to configure the cache?
Several observations:
I cannot add
<cache.../>
elements to the mappings since this would break the other applications which do not configure such a cache and which are not under my influence:Second-level cache is not enabled for usage [hibernate.cache.use_second_level_cache | hibernate.cache.use_query_cache]
- I can't find a way to activate an entity for caching outside of its mapping. Setting up a cache region for an entity in
ehcache.xml
does not help - Even if I could change all the other applications and add
<cache.../>
to the entity mappings, it does not work to disable the cache by settinghibernate.cache.use_second_level_cache=false
although it is said so in http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html, table 3.5
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您可以使用
元素在hibernate.cfg.xml
而不是实体映射中配置缓存,请参阅 3.8。 XML 配置文件。我想您有能力创建一个使用现有映射的自定义
hibernate.cfg.xml
,如果没有,也有Configuration.setCacheConcurrencyStrategy()
方法可能会有所帮助。It looks like you can use
<class-cache>
elements to configure caching inhibernate.cfg.xml
rather than in entity mappings, see 3.8. XML configuration file.I guess you can afford creating a custom
hibernate.cfg.xml
that would use existing mappings, and if not, there areConfiguration.setCacheConcurrencyStrategy()
methods that might help as well.