试图捕获ehcache Element ClassCastException

时间:2014-12-10 17:14:25

标签: java exception-handling seam ehcache classcastexception

我在使用ehcache尝试缓存比我设置的存储空间大的表时遇到问题。虽然应用程序不会失败(因为它最终在数据库中执行查询并返回数据),但我的日志充满了ClassCastException。

我不想更改设置,因为它会再次发生,我想捕获ClassCastException,但它不起作用。 (我尝试使用接缝组件过滤异常,并在特定的位置捕获异常)

版本是:Seam 2.2.2,Hibernate 3.3.3和ehCache 1.5

ERROR [user:] [DiskStore.java/get] – com.milestone.model.PersonItemCache: 
Could not read disk store element for key com.milestone.model.PersonItem#438480. 
Error was net.sf.ehcache.Element cannot be cast to net.sf.ehcache.Element
java.lang.ClassCastException: net.sf.ehcache.Element cannot be cast to net.sf.ehcache.Element
at net.sf.ehcache.store.DiskStore.loadElementFromDiskElement(DiskStore.java:302)
at net.sf.ehcache.store.DiskStore.get(DiskStore.java:257)
at net.sf.ehcache.Cache.searchInDiskStore(Cache.java:1202)
at net.sf.ehcache.Cache.get(Cache.java:803)
at org.hibernate.cache.EhCache.get(EhCache.java:80)
at org.hibernate.cache.ReadWriteCache.put(ReadWriteCache.java:178)
at org.hibernate.cache.impl.bridge.EntityAccessStrategyAdapter.putFromLoad(EntityAccessStrategyAdapter.java:68)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:179)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:877)
at org.hibernate.loader.Loader.doQuery(Loader.java:752)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.loadCollection(Loader.java:2019)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:59)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:587)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:83)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1744)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:366)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:108)
at org.hibernate.collection.AbstractPersistentCollection.readElementExistence(AbstractPersistentCollection.java:164)
at org.hibernate.collection.PersistentBag.contains(PersistentBag.java:262)
at com.milestone.person.PersonItemController.addAsFans(PersonItemController.java:141)

1 个答案:

答案 0 :(得分:1)

您的例外是ClassCastException: net.sf.ehcache.Element cannot be cast to net.sf.ehcache.Element这表明存在更大的问题。你很可能在classpath中有2个ehcace核心或相关的jar。捕获异常不是解决方案。不应该首先例外。