我从以下两个类中收到序列化兼容性错误。只有父类CommericalCustomer 实现了序列化。如下所示,当具有父/子关系时,使用可序列化接口的正确方法是什么?
public class CachedCommercialCustomers extends CommercialCustomer {
}
public class CommercialCustomer implements Serializable {
private static final long serialVersionUID = 1L;
}
例外:
[#|2013-01-02T05:01:02.553-0800|SEVERE|glassfish3.1.2|com.hazelcast.nio.AbstractSerializer|_ThreadID=10;_ThreadName=Thread-2;|spot.api.model.vo.backoffice.CachedCommercialCustomers; local class incompatible: stream classdesc serialVersionUID = -2672531984245897526, local class serialVersionUID = -743225273062282831
java.io.InvalidClassException: com.sample.CachedCommercialCustomers; local class incompatible: stream classdesc serialVersionUID = -2672531984245897526, local class serialVersionUID = -743225273062282831
at java.io.ObjectStreamClass.initNonProxy(ObjectStreamClass.java:579)
at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1600)
at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1513)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1749)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1346)
at java.io.ObjectInputStream.readUnshared(ObjectInputStream.java:458)
at com.hazelcast.nio.DefaultSerializer$ObjectSerializer.readNormal(DefaultSerializer.java:383)
at com.hazelcast.nio.DefaultSerializer$ObjectSerializer.read(DefaultSerializer.java:353)
at com.hazelcast.nio.DefaultSerializer.read(DefaultSerializer.java:134)
at com.hazelcast.nio.CustomSerializerAdapter.read(CustomSerializerAdapter.java:33)
at com.hazelcast.nio.AbstractSerializer.toObject(AbstractSerializer.java:116)
at com.hazelcast.nio.AbstractSerializer.toObject(AbstractSerializer.java:146)
at com.hazelcast.nio.Serializer.readObject(Serializer.java:72)
at com.hazelcast.impl.ThreadContext.toObject(ThreadContext.java:103)
at com.hazelcast.nio.IOUtil.toObject(IOUtil.java:149)
at com.hazelcast.impl.BaseManager$RequestBasedCall.getResultAsObject(BaseManager.java:384)
at com.hazelcast.impl.BaseManager$ResponseQueueCall.getResultAsObject(BaseManager.java:455)
at com.hazelcast.impl.BaseManager$RequestBasedCall.getResultAsObject(BaseManager.java:368)
at com.hazelcast.impl.BaseManager$ResponseQueueCall.getResultAsObject(BaseManager.java:455)