无法从DB4O反序列化对象

时间:2014-04-30 14:39:12

标签: java serialization enums deserialization db4o

有没有人在从DB4O读取对象时遇到这种异常? 或者你可以解释一下会出现什么问题吗?在我看来,它对Enum对象的反序列化有问题,但不明白为什么我尝试使用示例项目来序列化/反序列化相同的对象并且它工作正常。

提前致谢。

线程中的异常" main" com.db4o.ext.Db4oException:JDKField java.lang.String:name     at com.db4o.reflect.jdk.JdkField.handleException(JdkField.java:82)     at com.db4o.reflect.jdk.JdkField.set(JdkField.java:64)     在com.db4o.internal.reflect.StrictFieldAccessor.set(StrictFieldAccessor.java:17)     在com.db4o.internal.FieldMetadata.set(FieldMetadata.java:830)     at com.db4o.internal.FieldMetadata.activate(FieldMetadata.java:641)     at com.db4o.internal.handlers.StandardReferenceTypeHandler $ 2.processAspect(StandardReferenceTypeHandler.java:92)     at com.db4o.internal.metadata.MarshallingInfoTraverseAspectCommand.processAspect(MarshallingInfoTraverseAspectCommand.java:52)     at com.db4o.internal.metadata.StandardAspectTraversalStrategy.traverseAllAspects(StandardAspectTraversalStrategy.java:24)     at com.db4o.internal.ClassMetadata.traverseAllAspects(ClassMetadata.java:2118)     at com.db4o.internal.handlers.StandardReferenceTypeHandler.traverseAllAspects(StandardReferenceTypeHandler.java:256)     at com.db4o.internal.handlers.StandardReferenceTypeHandler.activateAspects(StandardReferenceTypeHandler.java:95)     at com.db4o.internal.handlers.StandardReferenceTypeHandler.activate(StandardReferenceTypeHandler.java:118)     在com.db4o.internal.Handlers4.activate(Handlers4.java:300)     at com.db4o.internal.ClassMetadata.instantiateFields(ClassMetadata.java:1355)     at com.db4o.internal.ClassMetadata.activate(ClassMetadata.java:1289)     在com.db4o.internal.ClassMetadata.instantiate(ClassMetadata.java:1247)     在com.db4o.internal.marshall.UnmarshallingContext.read(UnmarshallingContext.java:70)     at com.db4o.internal.ObjectReference.read(ObjectReference.java:306)     at com.db4o.internal.ObjectReference.readForActivation(ObjectReference.java:136)     at com.db4o.internal.ObjectReference.activateInternal(ObjectReference.java:132)     at com.db4o.internal.ObjectContainerBase.processedByImmediateActivation(ObjectContainerBase.java:1857)     at com.db4o.internal.ObjectContainerBase.stillToActivate(ObjectContainerBase.java:1833)     at com.db4o.internal.marshall.AbstractReadContext.readObject(AbstractReadContext.java:83)     at com.db4o.internal.marshall.AbstractReadContext.readAtCurrentSeekPosition(AbstractReadContext.java:48)     at com.db4o.internal.marshall.AbstractReadContext $ 1.run(AbstractReadContext.java:40)     at com.db4o.internal.marshall.SlotFormat.doWithSlotIndirection(SlotFormat.java:64)     at com.db4o.internal.marshall.AbstractReadContext.readObject(AbstractReadContext.java:38)     在com.db4o.internal.marshall.AbstractReadContext.read(AbstractReadContext.java:30)     at com.db4o.internal.FieldMetadata.read(FieldMetadata.java:793)     at com.db4o.internal.FieldMetadata.activate(FieldMetadata.java:639)     at com.db4o.internal.handlers.StandardReferenceTypeHandler $ 2.processAspect(StandardReferenceTypeHandler.java:92)     at com.db4o.internal.metadata.MarshallingInfoTraverseAspectCommand.processAspect(MarshallingInfoTraverseAspectCommand.java:52)     at com.db4o.internal.metadata.StandardAspectTraversalStrategy.traverseAllAspects(StandardAspectTraversalStrategy.java:24)     at com.db4o.internal.ClassMetadata.traverseAllAspects(ClassMetadata.java:2118)     at com.db4o.internal.handlers.StandardReferenceTypeHandler.traverseAllAspects(StandardReferenceTypeHandler.java:256)     at com.db4o.internal.handlers.StandardReferenceTypeHandler.activateAspects(StandardReferenceTypeHandler.java:95)     at com.db4o.internal.handlers.StandardReferenceTypeHandler.activate(StandardReferenceTypeHandler.java:118)     在com.db4o.internal.Handlers4.activate(Handlers4.java:300)     at com.db4o.internal.ClassMetadata.instantiateFields(ClassMetadata.java:1355)     at com.db4o.internal.ClassMetadata.activate(ClassMetadata.java:1289)     在com.db4o.internal.ClassMetadata.instantiate(ClassMetadata.java:1247)     在com.db4o.internal.marshall.UnmarshallingContext.read(UnmarshallingContext.java:70)     at com.db4o.internal.ObjectReference.read(ObjectReference.java:306)     at com.db4o.internal.ObjectReference.readForActivation(ObjectReference.java:136)     at com.db4o.internal.ObjectReference.activateInternal(ObjectReference.java:132)     at com.db4o.internal.ObjectContainerBase.processedByImmediateActivation(ObjectContainerBase.java:1857)     at com.db4o.internal.ObjectContainerBase.stillToActivate(ObjectContainerBase.java:1833)     at com.db4o.internal.marshall.AbstractReadContext.readObject(AbstractReadContext.java:83)     at com.db4o.internal.marshall.AbstractReadContext.readAtCurrentSeekPosition(AbstractReadContext.java:48)     at com.db4o.internal.OpenTypeHandler.read(OpenTypeHandler.java:175)     at com.db4o.internal.Handlers4.readValueType(Handlers4.java:309)     at com.db4o.internal.marshall.AbstractReadContext.readAtCurrentSeekPosition(AbstractReadContext.java:50)     at com.db4o.internal.marshall.AbstractReadContext $ 1.run(AbstractReadContext.java:40)     at com.db4o.internal.marshall.SlotFormat.doWithSlotIndirection(SlotFormat.java:64)     at com.db4o.internal.marshall.AbstractReadContext.readObject(AbstractReadContext.java:38)     在com.db4o.internal.marshall.AbstractReadContext.read(AbstractReadContext.java:30)     at com.db4o.internal.FieldMetadata.read(FieldMetadata.java:793)     at com.db4o.internal.FieldMetadata.activate(FieldMetadata.java:639)     at com.db4o.internal.handlers.StandardReferenceTypeHandler $ 2.processAspect(StandardReferenceTypeHandler.java:92)     at com.db4o.internal.metadata.MarshallingInfoTraverseAspectCommand.processAspect(MarshallingInfoTraverseAspectCommand.java:52)     at com.db4o.internal.metadata.StandardAspectTraversalStrategy.traverseAllAspects(StandardAspectTraversalStrategy.java:24)     at com.db4o.internal.ClassMetadata.traverseAllAspects(ClassMetadata.java:2118)     at com.db4o.internal.handlers.StandardReferenceTypeHandler.traverseAllAspects(StandardReferenceTypeHandler.java:256)     at com.db4o.internal.handlers.StandardReferenceTypeHandler.activateAspects(StandardReferenceTypeHandler.java:95)     at com.db4o.internal.handlers.StandardReferenceTypeHandler.activate(StandardReferenceTypeHandler.java:118)     在com.db4o.internal.Handlers4.activate(Handlers4.java:300)     at com.db4o.internal.ClassMetadata.instantiateFields(ClassMetadata.java:1355)     at com.db4o.internal.ClassMetadata.activate(ClassMetadata.java:1289)     在com.db4o.internal.ClassMetadata.instantiate(ClassMetadata.java:1247)     在com.db4o.internal.marshall.UnmarshallingContext.read(UnmarshallingContext.java:70)     at com.db4o.internal.ObjectReference.read(ObjectReference.java:306)     at com.db4o.internal.ObjectReference.readForActivation(ObjectReference.java:136)     at com.db4o.internal.ObjectReference.activateInternal(ObjectReference.java:132)     at com.db4o.internal.ObjectContainerBase.processedByImmediateActivation(ObjectContainerBase.java:1857)     at com.db4o.internal.ObjectContainerBase.stillToActivate(ObjectContainerBase.java:1833)     at com.db4o.internal.marshall.AbstractReadContext.readObject(AbstractReadContext.java:83)     at com.db4o.internal.marshall.AbstractReadContext.readAtCurrentSeekPosition(AbstractReadContext.java:48)     at com.db4o.internal.OpenTypeHandler.read(OpenTypeHandler.java:175)     at com.db4o.internal.Handlers4.readValueType(Handlers4.java:309)     at com.db4o.internal.marshall.AbstractReadContext.readAtCurrentSeekPosition(AbstractReadContext.java:50)     at com.db4o.internal.marshall.AbstractReadContext $ 1.run(AbstractReadContext.java:40)     at com.db4o.internal.marshall.SlotFormat.doWithSlotIndirection(SlotFormat.java:64)     at com.db4o.internal.marshall.AbstractReadContext.readObject(AbstractReadContext.java:38)     在com.db4o.internal.marshall.AbstractReadContext.read(AbstractReadContext.java:30)     at com.db4o.internal.FieldMetadata.read(FieldMetadata.java:793)     at com.db4o.internal.FieldMetadata.activate(FieldMetadata.java:639)     at com.db4o.internal.handlers.StandardReferenceTypeHandler $ 2.processAspect(StandardReferenceTypeHandler.java:92)     at com.db4o.internal.metadata.MarshallingInfoTraverseAspectCommand.processAspect(MarshallingInfoTraverseAspectCommand.java:52)     at com.db4o.internal.metadata.StandardAspectTraversalStrategy.traverseAllAspects(StandardAspectTraversalStrategy.java:24)     at com.db4o.internal.ClassMetadata.traverseAllAspects(ClassMetadata.java:2118)     at com.db4o.internal.handlers.StandardReferenceTypeHandler.traverseAllAspects(StandardReferenceTypeHandler.java:256)     at com.db4o.internal.handlers.StandardReferenceTypeHandler.activateAspects(StandardReferenceTypeHandler.java:95)     at com.db4o.internal.handlers.StandardReferenceTypeHandler.activate(StandardReferenceTypeHandler.java:118)     在com.db4o.internal.Handlers4.activate(Handlers4.java:300)     at com.db4o.internal.ClassMetadata.instantiateFields(ClassMetadata.java:1355)     at com.db4o.internal.ClassMetadata.activate(ClassMetadata.java:1289)     在com.db4o.internal.ClassMetadata.instantiate(ClassMetadata.java:1237)     在com.db4o.internal.marshall.UnmarshallingContext.read(UnmarshallingContext.java:70)     at com.db4o.internal.ObjectReference.read(ObjectReference.java:306)     at com.db4o.internal.ObjectReference.read(ObjectReference.java:292)     at com.db4o.internal.ObjectContainerBase $ 8.apply(ObjectContainerBase.java:901)     at com.db4o.internal.ObjectContainerBase $ 8.apply(ObjectContainerBase.java:899)     at com.db4o.internal.ObjectContainerBase.asTopLevelCall(ObjectContainerBase.java:431)     at com.db4o.internal.ObjectContainerBase.readActivatedObjectNotInCache(ObjectContainerBase.java:899)     at com.db4o.internal.query.result.AbstractQueryResult.activatedObject(AbstractQueryResult.java:35)     at com.db4o.internal.query.result.AbstractQueryResult $ 1.map(AbstractQueryResult.java:63)     在com.db4o.foundation.MappingIterator.moveNext(MappingIterator.java:30)     在com.db4o.foundation.Iterable4Adaptor.moveNext(Iterable4Adaptor.java:46)     在com.db4o.foundation.Iterable4Adaptor.hasNext(Iterable4Adaptor.java:28)     at com.db4o.internal.query.result.StatefulQueryResult.hasNext(StatefulQueryResult.java:42)     at com.db4o.internal.query.ObjectSetFacade.hasNext(ObjectSetFacade.java:61)     在com.example.main.RunMe.main(RunMe.java:70) 引起:java.lang.IllegalArgumentException:无法将最终的java.lang.String字段java.lang.Enum.name设置为com.db4o.reflect.generic.GenericObject     at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:164)     at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:168)     at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:55)     at sun.reflect.UnsafeQualifiedObjectFieldAccessorImpl.set(UnsafeQualifiedObjectFieldAccessorImpl.java:77)     在java.lang.reflect.Field.set(Field.java:741)     在com.db4o.reflect.jdk.JdkField.set(JdkField.java:62)     ......再多110个

2 个答案:

答案 0 :(得分:0)

如果将来有人会遇到类似的问题,我终于找到了根本原因。我序列化了对象" Person"与enum"状态"作为DB4O中的属性。一旦我尝试阅读它,我使用了以下内容:

ObjectSet<Object> allObjectsFromDb4o = db4OConnection.queryByExample(null); 

获取所有对象并将其与内存存储器同步。但是我误解了数据是如何序列化的...所以基本上不仅仅是我的对象&#34; Person&#34;还有枚举&#34;状态&#34;坚持了下来。因此,当我尝试从DB4O读取所有对象,然后将它们转换为我的&#34; Person&#34;。一旦我反序列化了#34; Person&#34;通过查询检索到的对象一切都很好......但是我试图投射枚举&#34;状态&#34;通过相同的查询检索,在那一刻我得到上面提到的奇怪的异常。 希望会帮助某人; - )。

答案 1 :(得分:0)

我遇到了与db4o类似的异常。

在我的情况下,我在持久性商店中有过时的类定义。我删除了陈旧的数据库文件,然后我能够按预期编写和读取。

如果您处于开发的早期阶段并且还没有“真实数据”,也许您也可以这样做。