Using hibernate in combination with something else that uses EHCache gives problems.
The 'something else' in my case is code of my own where I need specific caching (using EHCache).
The problem can be described as follows: EHCache provides a CacheManager, which (in version 1.1) is a singleton. The CacheManager is used to manage caches (creating new caches, constructing previously configured caches, deleting caches, ...). The CacheManager also provides a shutdown method that will dispose all caches managed by the CacheManager. As the CacheManager is a singleton, 'all caches' really means all caches in the running JVM.
Now the problem (I think) is that in hibernate the EhCacheProvider (a hibernate class) calls this shutdown method in its stop method, like this:
public void stop() {
if (manager != null) {
manager.shutdown();
manager = null;
}
}
This causes all caches to be disposed, including the caches that were not created or used by hibernate.
A solution would be to not call the shutdown method on the CacheManager. but to call removeCache(String name) for every cache hibernate actually used.
Hibernate version:
3.1.2
EhCache version:
1.1
Full stack trace of any exception that occurs:
My caches get disposed. so when I try to use them I get stack traces like
(ntc.nms.* is my own code)
java.lang.IllegalStateException: The ntc.nms.pmt.metric.MetricCache@25a649 Cache is not alive.
at net.sf.ehcache.Cache.checkStatus(Cache.java:713)
at net.sf.ehcache.Cache.getSize(Cache.java:655)
at ntc.nms.pmt.metric.MetricCache.size(MetricCache.java:128)
at ntc.nms.pmt.metric.MetricCache.verifyCacheSize(MetricCache.java:321)
at ntc.nms.pmt.metric.MetricCache.addAll(MetricCache.java:209)
at ntc.nms.pmt.monitor.MultiMonitorMetric.deriveMetrics(MultiMonitorMetric.java:215)
at ntc.nms.pmt.monitor.MultiMonitorMetric.recoverMetrics(MultiMonitorMetric.java:186)
at ntc.nms.pmt.monitor.MultiMonitorMetric.scan(MultiMonitorMetric.java:109)
at ntc.nms.framework.performance.Scanner$1.run(Scanner.java:104)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
|