在JBoss 4.2上使用JPA启用Hibernate二级缓存 [英] Enabling Hibernate second-level cache with JPA on JBoss 4.2

查看:129
本文介绍了在JBoss 4.2上使用JPA启用Hibernate二级缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用Java持久性API(注释实体)时,启用Hibernate的二级缓存所需的步骤是什么?我如何检查它的工作?我使用JBoss 4.2.2.GA。

从Hibernate文档看来,我需要启用缓存并在持久性中指定缓存提供程序.xml ,如:

 < property name =hibernate.cache.use_second_level_cache
value =true/>
< property name =hibernate.cache.provider_class
value =org.hibernate.cache.HashtableCacheProvider/>

还需要什么?我需要将 @Cache 注释添加到我的JPA实体吗?



如何判断缓存是否正常工作?我曾尝试在运行查询后访问缓存统计信息,但是 Statistics.getSecondLevelCacheStatistics 返回null,可能是因为我不知道要使用哪个'region'名称。


What are the steps required to enable Hibernate's second-level cache, when using the Java Persistence API (annotated entities)? How do I check that it's working? I'm using JBoss 4.2.2.GA.

From the Hibernate documentation, it seems that I need to enable the cache and specify a cache provider in persistence.xml, like:

<property name="hibernate.cache.use_second_level_cache"
          value="true" /> 
<property name="hibernate.cache.provider_class" 
          value="org.hibernate.cache.HashtableCacheProvider" /> 

What else is required? Do I need to add @Cache annotations to my JPA entities?

How can I tell if the cache is working? I have tried accessing cache statistics after running a Query, but Statistics.getSecondLevelCacheStatistics returns null, perhaps because I don't know what 'region' name to use.

解决方案

I believe you need to add the cache annotations to tell hibernate how to use the second-level cache (read-only, read-write, etc). This was the case in my app (using spring / traditional hibernate and ehcache, so your mileage may vary). Once the caches were indicated, I started seeing messages that they were in use from hibernate.

这篇关于在JBoss 4.2上使用JPA启用Hibernate二级缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆