Hibernate复制了Ehcache

时间:2016-04-15 13:20:44

标签: hibernate jpa ehcache

我有一个使用JSF Spring JPA2.1 Hibernate 5.1和ehcache 2.10构建的应用程序 我需要创建一个复制缓存,因为我想创建一个带有两个节点的glassfish4.1集群,并且两个节点保持同步,其中与二级缓存有关,尤其是弹簧安全使用的acl缓存。 这就是我的persistence.xml文件的样子:

<persistence-unit name="CCPU" transaction-type="JTA"> 
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>         
    <jta-data-source>jdbc/contactCenter</jta-data-source>       
    <properties>
        <property name="hibernate.connection.autocommit" value="false" />
        <property name="hibernate.show_sql" value="false"/>
        <property name="hibernate.format_sql" value="false"/>
        <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>

        <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.SunONETransactionManagerLookup" />
        <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform" />

        <property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory" />
        <property name="hibernate.cache.use_query_cache" value="true"/>
        <property name="hibernate.cache.use_second_level_cache" value="true"/>

        <property name="hibernate.cache.provider_configuration_file_resource_path" value="ehcache.xml"/>
        <property name="hibernate.cache.provider_class" value="org.hibernate.cache.ehcache.SingletonEhCacheProvider"/>           
        <property name="hibernate.generate_statistics" value="true"/>
        <property name="hibernate.session.events.log" value="false"/>

    </properties>       
</persistence-unit>

这就是我的ehcache文件的样子:

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:noNamespaceSchemaLocation="http://www.ehcache.org/ehcache.xsd" 
     updateCheck="false" 
     monitoring="autodetect" 
     maxBytesLocalHeap="2048M"
     >              
 <cacheManagerPeerProviderFactory 
class="net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory" 
properties="peerDiscovery=automatic, multicastGroupAddress=230.0.0.1, multicastGroupPort=4446, timeToLive=32"/>

<!-- Configure a cache manager peer listener that listens for messages from peers -->
<cacheManagerPeerListenerFactory class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory"
        properties="hostName=localhost, port=40001,socketTimeoutMillis=2000"/>


<!-- elemets expire in one our -->
<defaultCache
        eternal="false"
        timeToIdleSeconds="1800"
        timeToLiveSeconds="3600"
        overflowToDisk="false"
        statistics="true"        
   >

    <!-- Configure a cache event listener to actually replicate changes to the other cache instances -->
    <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
        properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true, replicateUpdatesViaCopy=false, replicateRemovals=true "/>
   </defaultCache>


   <cache name="aclCache"
        eternal="false"
        timeToIdleSeconds="600"
        timeToLiveSeconds="3600"
        overflowToDisk="false"
        statistics="true"
        >
        <!-- Configure a cache event listener to actually replicate changes to the other cache instances -->
    <cacheEventListenerFactory class="net.sf.ehcache.distribution.RMICacheReplicatorFactory"
        properties="replicateAsynchronously=true, replicatePuts=true, replicateUpdates=true, replicateUpdatesViaCopy=false, replicateRemovals=true "/>
    </cache>

问题是,当我启动应用程序时,我在使用Hibernate SessionFactory的同时引发了这个异常:

Caused by: net.sf.ehcache.CacheException: java.lang.ClassCastException: net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory cannot be cast to net.sf.ehcache.distribution.CacheManagerPeerListenerFactory
at net.sf.ehcache.CacheManager.init(CacheManager.java:426)
at net.sf.ehcache.CacheManager.<init>(CacheManager.java:270)
at net.sf.ehcache.CacheManager.newInstance(CacheManager.java:1116)
at net.sf.ehcache.CacheManager.newInstance(CacheManager.java:892)
at net.sf.ehcache.CacheManager.create(CacheManager.java:873)
at org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory.start(SingletonEhCacheRegionFactory.java:65)
... 71 more
Caused by: java.lang.ClassCastException: net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory cannot be cast to net.sf.ehcache.distribution.CacheManagerPeerListenerFactory
at net.sf.ehcache.config.ConfigurationHelper.createCachePeerListeners(ConfigurationHelper.java:163)
at net.sf.ehcache.CacheManager.configure(CacheManager.java:786)
at net.sf.ehcache.CacheManager.doInit(CacheManager.java:471)
at net.sf.ehcache.CacheManager.init(CacheManager.java:395)
... 76 more

P.S - 我使用Glassfish 4.1.1。我尝试调试一点这个问题,似乎在WebApplicationClassLoader中的某处抛出了异常。该类最初由EhCacheDefaultClassLoader ...

加载

0 个答案:

没有答案