【发布时间】:2012-09-27 04:05:06
【问题描述】:
我正在使用 EhCache 来存储我的应用程序对象的有限大小缓存,但是在升级其版本后,我在使用 cache.get(...) 时遇到了这个异常:
java.lang.ClassCastException: net.sf.ehcache.store.chm.SelectableConcurrentHashMap$DummyPinnedKey cannot be cast to br.com.project.util.VttcElement
有人知道我们是否应该在缓存键中实现任何新接口吗?
这是我改编的代码:
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
private VttcElementCache() {
CacheManager cacheManager = CacheManager.create(METAINFFileLoader.getInputStream("ehcache.xml"));
cache = cacheManager.getCache("br.com.project.util.VttcElement");
}
private void load(int id, long idf) {
cache.put(new Element(new VttcElement(id, idf), "1"));
}
private String get(VttcElement vttcElement) {
Element element = cache.get(vttcElement); //The exception is thrown here!
(String) return elemente.getValue();
}
【问题讨论】:
-
能否提供一些代码?
-
当然,我用它编辑了我的问题。谢谢。
-
抱歉,我必须用真正的异常抛出点进行编辑。它在 cache.get 上。
-
那里没有你应该实现的东西,但是有一个版本的错误。我需要仔细检查...但是您看到的异常与固定有关。您似乎没有这样做...您是否使用具有相同缓存的 Hibernate ?