我正在尝试使用EhCache启用二级缓存,但在我的服务器启动时遇到问题 . 当我为我的DTO类指定@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)时,我收到以下错误:
16:20:42,882 ERROR [org.jboss.as.controller.management-operation](控制器启动线程)JBAS014612:操作(“部署”)失败 - 地址:([(“deploy ment”=>“PORTAL.ear “)] - 失败描述:{”JBAS014671:Failed services“=> {”jboss.persistenceunit . \“PORTAL.ear#AppPU \”“=>”org.jb oss.msc.service.StartException in service jboss . persistenceunit . \“PORTAL.ear #AppPU \”:javax.persistence.PersistenceException:[PersistenceUnit:AppPU]无法构建EntityManagerFactory引起:javax.persistence.PersistenceException:[PersistenceUnit:AppPU]无法构建EntityManagerFactory引起:org . hibernate.cache.CacheException:不支持的访问类型[读写]“}}
如果我使用CacheConcurrencyStrategy.READ_ONLY,我没有遇到任何启动问题 .
Below is my persistence.xml:
<persistence-unit name="AppPU" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/myDS</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
<properties>
<!-- Auto-detect entity classes -->
<property name="hibernate.archive.autodetection" value="class, hbm"/>
<!-- Print sql executed - useful for debugging -->
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.format_sql" value="false"/>
<!-- Properties for Hibernate -->
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.cache.provider_class" value="net.sf.Ehcache.hibernate.SingletonEhcacheProvider"/>
<!-- <property name="hibernate.cache.region.factory_class" value="net.sf.ehcache.hibernate.EhCacheRegionFactory"/> -->
<property name="net.sf.Ehcache.configurationResourceName" value="/ehcache.xml"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.generate_statistics" value="true"/>
</properties>
</persistence-unit>
我想使用READ_WRITE来启用二级缓存 .
有人可以帮我解决这个问题吗?提前致谢 .
1 回答
To configure ehcache, you need to do two steps :
配置Hibernate进行二级缓存指定二级缓存提供程序
Hibernate 4.x and above
Hibernate 3.3 and above
Hibernate 3.2 and below
reference