我使用EhCache实现了Hibernate 2nd Level并使用指令注册了缓存事件监听器
此处:http://ehcache.org/documentation/apis/cache-event-listeners
CacheEventListenerFactory和CacheEventListener有效,但我可以知道如何从元素中检索出我的实体吗?
我试过
public void notifyElementPut(final Ehcache cache, final Element element) throws CacheException{
ABEEntity entity = (ABCEntity)element.getObjectValue(); // throws ClassCastException
}
它不断抛出类强制转换异常。我可以知道ObjectValue被包裹了吗?我相信是一个阵列,但我找不到任何信息。
有人可以提供答案和文件吗?
文档比答案更重要????
答案 0 :(得分:0)
不幸的是,你不会通过这样做来访问你的实体对象,因为Hibernate 2nd lvl缓存不会存储实体,而是存在称为脱水状态的东西。
有关详细信息,请参阅此Which Classes are Cached in second level cache in hibernate。