EhCache 缓存嵌入对象问题
< 返回列表时间: 2012-03-10来源:开源中国
HDC调试需求开发(15万预算),能者速来!>>>
问题是这样的
我想把下面的book对像(含Factory属性)使用缓存ehcache缓存起来,但是总是报错,相信是我的使用方式不对,或是此路不通吧,有没有什么好的办法可以实现这样的想法呢,多谢了
public class Factory { private String Address; public Factory(String address) { super(); Address = address; } public String getAddress() { return Address; } public void setAddress(String address) { Address = address; } }



public class Book implements Serializable { private String bookName; private Factory factory; public Factory getFactory() { return factory; } public void setFactory(Factory factory) { this.factory = factory; } public Book(String bookName) { this.bookName = bookName; } public String getBookName() { return bookName; } }
Ehcache使用方法

CacheManager manager1 = new CacheManager(); String[] cacheNamesForManager1 = manager1.getCacheNames(); Cache cache = manager1.getCache("sampleCache1"); Book b = new Book("Music Book"); b.setFactory(new Factory("china")); Element element1 = new Element("book", b); cache.put(element1);
报错内容

012-3-10 23:23:06 net.sf.ehcache.store.disk.DiskStorageFactory$DiskWriteTask call 严重: Disk Write of book failed: java.io.NotSerializableException: com.domain.ehcache.Factory at java.io.ObjectOutputStream.writeObject0(Unknown Source) at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source) at java.io.ObjectOutputStream.writeSerialData(Unknown Source) at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source) at java.io.ObjectOutputStream.writeObject0(Unknown Source) at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source) at java.io.ObjectOutputStream.defaultWriteObject(Unknown Source) at net.sf.ehcache.Element.writeObject(Element.java:797) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at java.io.ObjectStreamClass.invokeWriteObject(Unknown Source) at java.io.ObjectOutputStream.writeSerialData(Unknown Source) at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source) at java.io.ObjectOutputStream.writeObject0(Unknown Source) at java.io.ObjectOutputStream.writeObject(Unknown Source) at net.sf.ehcache.util.MemoryEfficientByteArrayOutputStream.serialize(MemoryEfficientByteArrayOutputStream.java:97) at net.sf.ehcache.store.disk.DiskStorageFactory.serializeElement(DiskStorageFactory.java:413) at net.sf.ehcache.store.disk.DiskStorageFactory.write(DiskStorageFactory.java:392) at net.sf.ehcache.store.disk.DiskStorageFactory$DiskWriteTask.call(DiskStorageFactory.java:493) at net.sf.ehcache.store.disk.DiskStorageFactory$PersistentDiskWriteTask.call(DiskStorageFactory.java:1154) at net.sf.ehcache.store.disk.DiskStorageFactory$PersistentDiskWriteTask.call(DiskStorageFactory.java:1138) at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown Source) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)



热门排行