2011-10-04 22 views
14

Después de configurar EhCache v2.4.5 como el segundo nivel de caché para hibernate v3.6.7 me aparece el siguiente error al intentar cargar todos los objetos de una entidad particular usando la sesión de hibernación. (No hay error para cargar los objetos por primera vez)EhCache + Hibernate Cache no está vivo

java.lang.IllegalStateException: The country Cache is not alive. 
at net.sf.ehcache.Cache.checkStatus(Cache.java:2438) 
at net.sf.ehcache.Cache.get(Cache.java:1541) 
at net.sf.ehcache.hibernate.regions.EhcacheTransactionalDataRegion.get(EhcacheTransactionalDataRegion.java:105) 
at net.sf.ehcache.hibernate.strategy.AbstractReadWriteEhcacheAccessStrategy.putFromLoad(AbstractReadWriteEhcacheAccessStrategy.java:90) 
at net.sf.ehcache.hibernate.nonstop.NonstopAwareEntityRegionAccessStrategy.putFromLoad(NonstopAwareEntityRegionAccessStrategy.java:180) 
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:195) 
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:982) 
at org.hibernate.loader.Loader.doQuery(Loader.java:857) 
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274) 
at org.hibernate.loader.Loader.doList(Loader.java:2533) 
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276) 
at org.hibernate.loader.Loader.list(Loader.java:2271) 
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:119) 
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1716) 
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347) 
at dataAccess.CountryDAO.loadAll(CountryDAO.java:80) 

Mi configuración de hibernación es:

<property name="hibernate.cache.region.factory_class"> 
     net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory 
</property> 
<property name="hibernate.cache.provider_configuration"> 
    /ehcache.xml 
</property> 
<property name="hibernate.cache.use_second_level_cache"> 
    true 
</property> 
<property name="hibernate.cache.use_query_cache"> 
    true 
</property> 

Mi configuración Ehcache es:

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="true" 
monitoring="autodetect" dynamicConfig="true"> 

<diskStore path="java.io.tmpdir" /> 

<transactionManagerLookup 
    class="net.sf.ehcache.transaction.manager.DefaultTransactionManagerLookup" 
    properties="jndiName=java:/TransactionManager" propertySeparator=";" /> 

<cacheManagerEventListenerFactory 
    class="" properties="" /> 

<defaultCache maxElementsInMemory="0" eternal="false" 
    overflowToDisk="true" timeToIdleSeconds="1200" timeToLiveSeconds="1200"> 
</defaultCache> 
<cache name="country" 
    maxElementsInMemory="300" eternal="false" overflowToDisk="false" 
    timeToIdleSeconds="12000" timeToLiveSeconds="12000" diskPersistent="false" 
    diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU" /> 
<cache name="city" 
    maxElementsInMemory="300" eternal="false" overflowToDisk="false" 
    timeToIdleSeconds="12000" timeToLiveSeconds="12000" diskPersistent="false" 
    diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU" /> 
</ehcache> 

no tengo ni idea de lo está yendo mal. ¿algunas ideas?

+0

es posible que también establezca la propiedad hibernate.cache.provider_class en net.sf.ehcache.hibernate.EhCacheProvider – frictionlesspulley

+0

¿Hay alguna razón por la que hace referencia a su archivo ehcache.xml como "/ehcache.xml", es Hibernate recogerlo? Si están en la misma ruta de clase, no tienes que hacer referencia a ella. – artgon

+0

También probé con EhCacheProvider, existe el mismo problema, y ​​sobre ehcache.xml tiene razón, hibernate lo recoge para que no cause ningún daño aunque sea redundante. – Saffar

Respuesta

4

No sé la razón real de por qué sucede esto, pero tengo una sugerencia para rastrearlo.

Al observar el código fuente de net.sf.ehcache.Cache, se puede ver que la marca 'viva' solo comprueba un indicador en memoria, Cache.cacheStatus. Debe ser sencillo ejecutar el código bajo el depurador y establecer un punto de interrupción en Cache.dispose() (donde el estado está configurado en Status.STATUS_SHUTDOWN) o incluso en Cache.CacheStatus.changeState() (para detectar cualquier transición de estado).

Es posible que haya un error con Hibernate, o puede ser su uso. De cualquier manera, debería ser capaz de encontrar exactamente quién está cambiando el estado de su caché a 'no vivo'.

Buena suerte.

0

No sé hibernate ehcache implementación tiene esta propiedad, pero cuando utilicé la solución de ehcache outbox recuperé el mismo problema y resolví con la configuración de propiedad compartida a falso en EhCacheManagerFactoryBean o EhCacheCacheManager frijoles.

Cuestiones relacionadas