While integrating two subsystems, we were forced to use multiple SessionFactory instances, which lead to trouble when interacting with our Hibernate second-level cache (Terracotta EhCache). Specifically:
for(CacheManager cm : CacheManager.ALL_CACHE_MANAGERS){
LOGGER.log(Level.DEBUG, "In cm " + cm.getName());
for(String cn : cm.getCacheNames()){
LOGGER.log(Level.DEBUG, "I have a cache called " + cn);
LOGGER.log(Level.DEBUG, "it's status is " + ms.getCache(cn).getStatus());
}
}
try{
myCollection.size();
}catch(IllegalStateException ise){
LOGGER.log(Level.FATAL, ise); //Triggered
}
The debug print-out shows STATUS_ALIVE
for cache "Foo" but the call to size()
throws an IllegalStateException
:
java.lang.IllegalStateException: The Foo Cache is not alive.
Currently, both SessionFactories are configured to use SingletonEhCacheRegionFactory
. If I switch the SessionFactories to use EhCacheRegionFactory
(non-singleton), what are the ramifications for cache behavior (specifically in a Web App context)?