简体   繁体   English

如何在jboss休眠状态下配置缓存? ? 并在kumud控制台中进行测试?

[英]how to configure cache in hibernate with jboss? ? And test as well in kumud console?

Does any one know, how to configure cache for hibernate with jboss ? 有谁知道如何通过jboss为休眠配置缓存?

My clear question is I am using JPA and Jboss. 我的明确问题是我正在使用JPA和Jboss。 Every time I call JPA method its creating entity and binding query. 每次我调用JPA方法时,都会创建它的实体和绑定查询。

My persistence properties are 我的持久性属性是

<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/>
<property name="hibernate.cache.provider_class"   value="net.sf.ehcache.hibernate.SingletonEhCacheProvider"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.use_query_cache" value="true"/>

And I am creating entity manager the way shown below: 我正在按以下所示方式创建实体管理器:

emf = Persistence.createEntityManagerFactory("pu");
em = emf.createEntityManager();
em = Persistence.createEntityManagerFactory("pu")
                        .createEntityManager();

Is there any nice way to manage entity manager resource insted create new every time or any property can set in persistance. 是否有任何好的方法来管理每次创建新的实体管理器资源或可以持久化设置的任何属性。 Remember it's JPA. 记住这是JPA。

The question is not clear, there are many second level cache providers for Hibernate and they are not application server specific. 问题尚不清楚,因为Hibernate有许多二级缓存提供程序 ,它们不是特定于应用程序服务器的。

To enable the second level cache, you need to set the following properties in Hibernate configuration file hibernate.cfg.xml : 要启用二级缓存,您需要在Hibernate配置文件hibernate.cfg.xml设置以下属性:

<property name="hibernate.cache.use_second_level_cache">true</property>

And if you want to also enable query result caching: 并且如果您还想启用查询结果缓存:

<property name="hibernate.cache.use_query_cache">true</property>

Then, declare the name of a class that implements org.hibernate.cache.CacheProvider - a cache provider - under the hibernate.cache.provider_class property. 然后,在hibernate.cache.provider_class属性下声明实现org.hibernate.cache.CacheProvider的类的名称-缓存提供程序。 For example, to use JBoss Cache 2: 例如,要使用JBoss Cache 2:

<property name="hibernate.cache.provider_class">org.hibernate.cache.jbc2.JBossCacheRegionFactory</property>

Of course, the JAR for the provider must be added to the application classpath. 当然,必须将提供程序的JAR添加到应用程序类路径中。

That's for the Hibernate side. 那是为了休眠。 Depending on the chosen cache provider, there might be additional configuration steps. 根据所选的缓存提供程序,可能会有其他配置步骤。 But as I said, there are many second level cache providers: EHCache, JBoss Cache, Infinispan , Hazelcast , Coherence , GigaSpace , etc. 但是正如我所说,有许多二级缓存提供程序:EHCache,JBoss Cache, InfinispanHazelcastCoherenceGigaSpace等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM