EhCache + Hibernate Cache is not alive
Asked Answered
U

3

19

After configuring EhCache v2.4.5 as the second level cache for hibernate v3.6.7 I get the following error while trying to load all objects of a particular entity using hibernate session. (There is no error for loading the objects for the first time)

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)

My hibernate configuration is:

<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>

My EhCache configuration is:

<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>

I have no clue what is going wrong. any ideas?

Upandcoming answered 4/10, 2011 at 10:42 Comment(10)
you might as well set the hibernate.cache.provider_class property to net.sf.ehcache.hibernate.EhCacheProviderRoane
Is there a reason why you're referencing your ehcache.xml file as "/ehcache.xml", is Hibernate picking it up? If they're in the same classpath, you don't have to reference it.Coadunate
I've also tried the EhCacheProvider the same problem exists, and about the ehcache.xml you are right, hibernate picks it up so it doesn't do any harm although it is redundant.Upandcoming
@Upandcoming : I've got the very same problem. But only in a particular case: A Jenkins instance running in a VM - VMWare ESXi (v4.0.0). It does not happen on my local environment. Neither does it happen in a VMWare Player VM. (Hibernate 3.6.9.Final EHCache 2.4.6). Did you find out what's wrong ?Highspirited
@Jan I have the same problem and case: Jenkings running an a VMWare ESXi environment. It works locallyYoungstown
I've got nothing new. It works when switching off the 2nd level and query caches. That's how it works now. But the final solution is probably to replace EHCache altogether. I was thinking about Infinispan. Heard lots of good things about it.Highspirited
Hit the same problem with Hibernate Search. Switching off the 2nd level caches did the trick. Copying the VM into a local VMPlayer doesn't help either. Neither does an upgrade of Jenkins or Hibernate. So it's probably a rare error condition on VMWare's VMs ?Highspirited
I got the same problem here. But no solution found in the web yet. Anyone?Jopa
I have same problem on HudsonRibosome
just restarting the server solved the problem..this occurs when the idle time exceeds the value given in the xml file..Automaton
M
6

I don't know the actual reason why this is happening, but I have a suggestion for tracking it down.

Looking at the source code for net.sf.ehcache.Cache, one can see that the 'alive' check just checks an in-memory flag, Cache.cacheStatus. It should be straightforward to run your code under the debugger, and set a breakpoint either in Cache.dispose() (where status is set to Status.STATUS_SHUTDOWN) or even in Cache.CacheStatus.changeState() (to catch any status transition).

You may find that there is in fact a bug with Hibernate, or it may be your usage. Either way, you should be able to find exactly who's changing the state of your cache to 'not alive'.

Good luck.

Metaprotein answered 29/1, 2013 at 14:26 Comment(0)
E
0

I don't know hibernate ehcache implementation has this property but when i used outofbox solution of ehcache i got same problem and solved with setting up shared property to false in EhCacheManagerFactoryBean or EhCacheCacheManager beans.

Excurrent answered 16/10, 2015 at 14:9 Comment(0)
I
0

I don't know the actual reason either. But I have a guess that it may happen due to multiple incompatible versions of EhCache in application classpath. Check this by inspecting dependency tree with the following maven command:

mvn dependency:tree '-Dincludes=*:*cache*'

(PowerShell syntax)

Iodometry answered 4/4, 2018 at 9:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.