Java 微流 - 合成 类 - PersistenceExceptionTypeNotPersistable
Java Microstream - Synthetic classes - PersistenceExceptionTypeNotPersistable
使用 Microstream 出现以下异常。
由引用静态内部 class 的 class 引起。
我该如何解决这个问题?
异常说明如下,但文档没有解释如何实现 PersistenceTypeResolver
Details: Synthetic classes ( etc.) are not reliably persistence since a simple reordering of source code elements would change the name identity of a class. For a type system that has to rely upon resolving types by their identifying name, this would silently cause a potentially fatal error. If handling synthetic classes (e.g. anonymous inner classes) is absolutely necessary, a custom one.microstream.persistence.types.PersistenceTypeResolver can be used to remove the exception and assume complete responsibility for correctly handling synthetic class names.
at one.microstream.persistence.types.Persistence.derivePersistentTypeName(Persistence.java:1083)
public static final AbstractAccompanyingPassenger DUMMY = new AbstractAccompanyingPassenger(MetaDataAccompanyingType.DUMMY) {
@Override
public AbstractAccompanyingPassenger clone() {
return DUMMY;
}};
Caused by: one.microstream.persistence.exceptions.PersistenceExceptionTypeNotPersistable: Type not persistable: "class net.atpco.metadata.summary.accompanied.MetaDataAccompanying". Details: Synthetic classes ( etc.) are not reliably persistence since a simple reordering of source code elements would change the name identity of a class. For a type system that has to rely upon resolving types by their identifying name, this would silently cause a potentially fatal error. If handling synthetic classes (e.g. anonymous inner classes) is absolutely necessary, a custom one.microstream.persistence.types.PersistenceTypeResolver can be used to remove the exception and assume complete responsibility for correctly handling synthetic class names.
at one.microstream.persistence.types.Persistence.derivePersistentTypeName(Persistence.java:1083)
at one.microstream.persistence.types.PersistenceTypeResolver.deriveTypeName(PersistenceTypeResolver.java:17)
at one.microstream.persistence.types.PersistenceTypeHandlerCreator$Abstract.deriveTypeName(PersistenceTypeHandlerCreator.java:73)
at one.microstream.persistence.binary.types.BinaryTypeHandlerCreator$Default.internalCreateTypeHandlerGeneric(BinaryTypeHandlerCreator.java:238)
at one.microstream.persistence.types.PersistenceTypeHandlerCreator$Abstract.createTypeHandlerGeneric(PersistenceTypeHandlerCreator.java:168)
at one.microstream.persistence.types.PersistenceTypeHandlerEnsurer$Default.ensureTypeHandler(PersistenceTypeHandlerEnsurer.java:199)
at one.microstream.persistence.internal.PersistenceTypeHandlerProviderCreating.ensureTypeHandler(PersistenceTypeHandlerProviderCreating.java:170)
at one.microstream.persistence.internal.PersistenceTypeHandlerProviderCreating.provideTypeHandler(PersistenceTypeHandlerProviderCreating.java:78)
at one.microstream.persistence.types.PersistenceTypeHandlerManager$Default.internalEnsureTypeHandler(PersistenceTypeHandlerManager.java:587)
at one.microstream.persistence.types.PersistenceTypeHandlerManager$Default.ensureTypeHandler(PersistenceTypeHandlerManager.java:357)
at one.microstream.persistence.types.PersistenceTypeHandlerManager$Default.ensureTypeHandler(PersistenceTypeHandlerManager.java:333)
at one.microstream.persistence.binary.types.BinaryStorer$Default.registerGuaranteed(BinaryStorer.java:557)
at one.microstream.persistence.binary.types.BinaryStorer$Default.registerLazyOptional(BinaryStorer.java:572)
at one.microstream.persistence.types.PersistenceObjectManager$Default.ensureObjectId(PersistenceObjectManager.java:182)
at one.microstream.persistence.binary.types.BinaryStorer$Default.register(BinaryStorer.java:591)
at one.microstream.persistence.binary.types.BinaryStorer$Default.apply(BinaryStorer.java:298)
at one.microstream.persistence.binary.types.BinaryValueFunctions.storeValueFromMemory(BinaryValueFunctions.java:147)
at one.microstream.persistence.binary.types.Binary.storeFixedSize(Binary.java:1149)
at one.microstream.persistence.binary.internal.AbstractBinaryHandlerReflective.store(AbstractBinaryHandlerReflective.java:497)
at one.microstream.persistence.binary.internal.AbstractBinaryHandlerReflective.store(AbstractBinaryHandlerReflective.java:1)
at one.microstream.persistence.binary.types.BinaryStorer$Default.storeItem(BinaryStorer.java:414)
at one.microstream.persistence.binary.types.BinaryStorer$Default.storeGraph(BinaryStorer.java:403)
at one.microstream.persistence.binary.types.BinaryStorer$Default.store(BinaryStorer.java:421)
at one.microstream.persistence.types.PersistenceManager$Default.store(PersistenceManager.java:274)
at one.microstream.storage.types.StorageConnection.store(StorageConnection.java:306)
at one.microstream.cache.CacheStore$Default.write(CacheStore.java:112)
由于异常状态持续合成 类 不受支持。
在你的情况下,重构你的 类 以摆脱那些合成 类 是唯一可靠的选择。
我找到了解决此问题的方法,无需更改 Java 对象图结构并具有合成 Classes/static 引用。
- 为具有合成 Classes/static 引用
的对象实施 CustomBinaryHandler
- 覆盖 store 方法
- 覆盖创建方法
- 覆盖 initializeState 方法
店铺
如果引用是对合成 Classes/static 引用,则创建对象的新实例并将引用设置为 'marker'。在我的情况下为空。不要更新传递给 store 方法的当前对象,确保创建一个克隆并修改适用的引用。然后调用 super.store()
创建
创建对象的空实例
初始化状态
- 检索对象的值
- 如果相关值具有 'marker',则将其设置为综合 Classes/static 参考值
- 创建一个克隆对象并填充值
- XReflect.copyFields从克隆到真实实例
public class ExampleTypeHandler extends CustomBinaryHandler<Example> {
private static Class<Example> handledType() {
return Example.class; // to get ".class" to work
}
//the fields to be persisted
BinaryField<Example> accompanying = Field(Object.class, Example::getAccompanying);
BinaryField<Example> resulting = Field(Object.class, Example::getResulting);
public ExampleTypeHandler()
{
super(handledType());
}
@Override
public void store(Binary data, Example dtl, long objectId, PersistenceStoreHandler<Binary> handler) {
if (dtl.getAccompanying() == MetaDataAccompanying.DUMMY) {
dtl = Example.of(dtl.getResulting(), null);
}
super.store(data, dtl, objectId, handler);
}
@Override
public Example create(final Binary data, final PersistenceLoadHandler handler) {
return Example.of(null, null);
}
@Override
public void initializeState(final Binary data, final Example instance, final PersistenceLoadHandler handler) {
//get the referenced Objects
Object accompanying = this.accompanying.readReference(data, handler);
String r = (String)this.resulting.readReference(data, handler);
if (accompanying == null) {
accompanying = MetaDataAccompanying.DUMMY;
}
MetaDataAccompanying a = (MetaDataAccompanying) accompanying;
Example dtl = Example.of(r, a);
XReflect.copyFields(dtl, instance);
}
}
使用 Microstream 出现以下异常。 由引用静态内部 class 的 class 引起。 我该如何解决这个问题?
异常说明如下,但文档没有解释如何实现 PersistenceTypeResolver
Details: Synthetic classes ( etc.) are not reliably persistence since a simple reordering of source code elements would change the name identity of a class. For a type system that has to rely upon resolving types by their identifying name, this would silently cause a potentially fatal error. If handling synthetic classes (e.g. anonymous inner classes) is absolutely necessary, a custom one.microstream.persistence.types.PersistenceTypeResolver can be used to remove the exception and assume complete responsibility for correctly handling synthetic class names. at one.microstream.persistence.types.Persistence.derivePersistentTypeName(Persistence.java:1083)
public static final AbstractAccompanyingPassenger DUMMY = new AbstractAccompanyingPassenger(MetaDataAccompanyingType.DUMMY) {
@Override
public AbstractAccompanyingPassenger clone() {
return DUMMY;
}};
Caused by: one.microstream.persistence.exceptions.PersistenceExceptionTypeNotPersistable: Type not persistable: "class net.atpco.metadata.summary.accompanied.MetaDataAccompanying". Details: Synthetic classes ( etc.) are not reliably persistence since a simple reordering of source code elements would change the name identity of a class. For a type system that has to rely upon resolving types by their identifying name, this would silently cause a potentially fatal error. If handling synthetic classes (e.g. anonymous inner classes) is absolutely necessary, a custom one.microstream.persistence.types.PersistenceTypeResolver can be used to remove the exception and assume complete responsibility for correctly handling synthetic class names.
at one.microstream.persistence.types.Persistence.derivePersistentTypeName(Persistence.java:1083)
at one.microstream.persistence.types.PersistenceTypeResolver.deriveTypeName(PersistenceTypeResolver.java:17)
at one.microstream.persistence.types.PersistenceTypeHandlerCreator$Abstract.deriveTypeName(PersistenceTypeHandlerCreator.java:73)
at one.microstream.persistence.binary.types.BinaryTypeHandlerCreator$Default.internalCreateTypeHandlerGeneric(BinaryTypeHandlerCreator.java:238)
at one.microstream.persistence.types.PersistenceTypeHandlerCreator$Abstract.createTypeHandlerGeneric(PersistenceTypeHandlerCreator.java:168)
at one.microstream.persistence.types.PersistenceTypeHandlerEnsurer$Default.ensureTypeHandler(PersistenceTypeHandlerEnsurer.java:199)
at one.microstream.persistence.internal.PersistenceTypeHandlerProviderCreating.ensureTypeHandler(PersistenceTypeHandlerProviderCreating.java:170)
at one.microstream.persistence.internal.PersistenceTypeHandlerProviderCreating.provideTypeHandler(PersistenceTypeHandlerProviderCreating.java:78)
at one.microstream.persistence.types.PersistenceTypeHandlerManager$Default.internalEnsureTypeHandler(PersistenceTypeHandlerManager.java:587)
at one.microstream.persistence.types.PersistenceTypeHandlerManager$Default.ensureTypeHandler(PersistenceTypeHandlerManager.java:357)
at one.microstream.persistence.types.PersistenceTypeHandlerManager$Default.ensureTypeHandler(PersistenceTypeHandlerManager.java:333)
at one.microstream.persistence.binary.types.BinaryStorer$Default.registerGuaranteed(BinaryStorer.java:557)
at one.microstream.persistence.binary.types.BinaryStorer$Default.registerLazyOptional(BinaryStorer.java:572)
at one.microstream.persistence.types.PersistenceObjectManager$Default.ensureObjectId(PersistenceObjectManager.java:182)
at one.microstream.persistence.binary.types.BinaryStorer$Default.register(BinaryStorer.java:591)
at one.microstream.persistence.binary.types.BinaryStorer$Default.apply(BinaryStorer.java:298)
at one.microstream.persistence.binary.types.BinaryValueFunctions.storeValueFromMemory(BinaryValueFunctions.java:147)
at one.microstream.persistence.binary.types.Binary.storeFixedSize(Binary.java:1149)
at one.microstream.persistence.binary.internal.AbstractBinaryHandlerReflective.store(AbstractBinaryHandlerReflective.java:497)
at one.microstream.persistence.binary.internal.AbstractBinaryHandlerReflective.store(AbstractBinaryHandlerReflective.java:1)
at one.microstream.persistence.binary.types.BinaryStorer$Default.storeItem(BinaryStorer.java:414)
at one.microstream.persistence.binary.types.BinaryStorer$Default.storeGraph(BinaryStorer.java:403)
at one.microstream.persistence.binary.types.BinaryStorer$Default.store(BinaryStorer.java:421)
at one.microstream.persistence.types.PersistenceManager$Default.store(PersistenceManager.java:274)
at one.microstream.storage.types.StorageConnection.store(StorageConnection.java:306)
at one.microstream.cache.CacheStore$Default.write(CacheStore.java:112)
由于异常状态持续合成 类 不受支持。 在你的情况下,重构你的 类 以摆脱那些合成 类 是唯一可靠的选择。
我找到了解决此问题的方法,无需更改 Java 对象图结构并具有合成 Classes/static 引用。
- 为具有合成 Classes/static 引用 的对象实施 CustomBinaryHandler
- 覆盖 store 方法
- 覆盖创建方法
- 覆盖 initializeState 方法
店铺
如果引用是对合成 Classes/static 引用,则创建对象的新实例并将引用设置为 'marker'。在我的情况下为空。不要更新传递给 store 方法的当前对象,确保创建一个克隆并修改适用的引用。然后调用 super.store()
创建
创建对象的空实例
初始化状态
- 检索对象的值
- 如果相关值具有 'marker',则将其设置为综合 Classes/static 参考值
- 创建一个克隆对象并填充值
- XReflect.copyFields从克隆到真实实例
public class ExampleTypeHandler extends CustomBinaryHandler<Example> {
private static Class<Example> handledType() {
return Example.class; // to get ".class" to work
}
//the fields to be persisted
BinaryField<Example> accompanying = Field(Object.class, Example::getAccompanying);
BinaryField<Example> resulting = Field(Object.class, Example::getResulting);
public ExampleTypeHandler()
{
super(handledType());
}
@Override
public void store(Binary data, Example dtl, long objectId, PersistenceStoreHandler<Binary> handler) {
if (dtl.getAccompanying() == MetaDataAccompanying.DUMMY) {
dtl = Example.of(dtl.getResulting(), null);
}
super.store(data, dtl, objectId, handler);
}
@Override
public Example create(final Binary data, final PersistenceLoadHandler handler) {
return Example.of(null, null);
}
@Override
public void initializeState(final Binary data, final Example instance, final PersistenceLoadHandler handler) {
//get the referenced Objects
Object accompanying = this.accompanying.readReference(data, handler);
String r = (String)this.resulting.readReference(data, handler);
if (accompanying == null) {
accompanying = MetaDataAccompanying.DUMMY;
}
MetaDataAccompanying a = (MetaDataAccompanying) accompanying;
Example dtl = Example.of(r, a);
XReflect.copyFields(dtl, instance);
}
}