我试图手动添加" org.hibernate.AnnotationException"到白名单。我试图在我的州类中实现serializationWhitelist接口。
假设我的状态类是Person类型,并且在其中定义了Address类型。每当我试图将状态从保险库中取出时,我都会收到此错误。或#34; org.hibernate.MappingException"。此外,当我的状态实现QueryableState时,我甚至无法持久保存数据。并得到以下错误
Starting as webserver: localhost:10007
Webserver started up in 59.55 sec
>> Generating transaction based on new create.
>> Verifying contract constraints.
>> Signing transaction with our private key.
>> Gathering the counterparty's signature.
>> Structural step change in child of Gathering the counterparty's signature.
>> Collecting signatures from counter-parties.
>> Done
>> Obtaining notary signature and recording transaction.
>> Structural step change in child of Obtaining notary signature and recording transaction.
>> Requesting signature by notary service
[1;31mE 14:01:20+0530 [qtp9538928-76] controller.DMSController.create - com.esotericsoftware.kryo.KryoException: Class org.hibernate.MappingException is not annotated or on the whitelist, so cannot be used in serialization
Serialization trace:
cause (rx.exceptions.OnErrorNotImplementedException)
throwable (rx.Notification)
[m java.util.concurrent.ExecutionException: com.esotericsoftware.kryo.KryoException: Class org.hibernate.MappingException is not annotated or on the whitelist, so cannot be used in serialization
Serialization trace:
cause (rx.exceptions.OnErrorNotImplementedException)
throwable (rx.Notification)
at java.util.concurrent.CompletableFuture.reportGet(Unknown Source) ~[?:1.8.0_151]
at java.util.concurrent.CompletableFuture.get(Unknown Source) ~[?:1.8.0_151]
at net.corda.core.internal.concurrent.CordaFutureImpl.get(CordaFutureImpl.kt) ~[corda-core-1.0.0.jar:?]
at com.den.managment.controller.DMSController.create(DMSController.java:124) [DisputeManagmentSystem.jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_151]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_151]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_151]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_151]
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81) [jersey-server-2.25.jar:?]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144) [jersey-server-2.25.jar:?]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161) [jersey-server-2.25.jar:?]
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:160) [jersey-server-2.25.jar:?]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99) [jersey-server-2.25.jar:?]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389) [jersey-server-2.25.jar:?]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347) [jersey-server-2.25.jar:?]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102) [jersey-server-2.25.jar:?]
at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:326) [jersey-server-2.25.jar:?]
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271) [jersey-common-2.25.jar:?]
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267) [jersey-common-2.25.jar:?]
at org.glassfish.jersey.internal.Errors.process(Errors.java:315) [jersey-common-2.25.jar:?]
at org.glassfish.jersey.internal.Errors.process(Errors.java:297) [jersey-common-2.25.jar:?]
at org.glassfish.jersey.internal.Errors.process(Errors.java:267) [jersey-common-2.25.jar:?]
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317) [jersey-common-2.25.jar:?]
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305) [jersey-server-2.25.jar:?]
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154) [jersey-server-2.25.jar:?]
at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:473) [jersey-container-servlet-core-2.25.jar:?]
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:427) [jersey-container-servlet-core-2.25.jar:?]
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:388) [jersey-container-servlet-core-2.25.jar:?]
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:341) [jersey-container-servlet-core-2.25.jar:?]
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:228) [jersey-container-servlet-core-2.25.jar:?]
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:845) [jetty-servlet-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:583) [jetty-servlet-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1174) [jetty-server-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:511) [jetty-servlet-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1106) [jetty-server-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) [jetty-server-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:119) [jetty-server-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134) [jetty-server-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.server.Server.handle(Server.java:524) [jetty-server-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:319) [jetty-server-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:253) [jetty-server-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:273) [jetty-io-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95) [jetty-io-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:93) [jetty-io-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.executeProduceConsume(ExecuteProduceConsume.java:303) [jetty-util-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceConsume(ExecuteProduceConsume.java:148) [jetty-util-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:136) [jetty-util-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:671) [jetty-util-9.3.9.v20160517.jar:9.3.9.v20160517]
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:589) [jetty-util-9.3.9.v20160517.jar:9.3.9.v20160517]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_151]
Caused by: com.esotericsoftware.kryo.KryoException: Class org.hibernate.MappingException is not annotated or on the whitelist, so cannot be used in serialization
Serialization trace:
cause (rx.exceptions.OnErrorNotImplementedException)
throwable (rx.Notification)
更新
public class SomeState implements LinearState,QueryableState{
private final UniqueIdentifier uid;
private final Party partyA;
private final Party partyB;
private final List<Address> addresses;
public SomeState(Party partyA, Party partyB, List<Address> addresses) {
super();
this.uid = new UniqueIdentifier();
this.partyA = partyA;
this.partyB = partyB;
this.addresses = addresses;
}
public Party getPartyA() {
return partyA;
}
public Party getPartyB() {
return partyB;
}
public List<Address> getAddresses() {
return addresses;
}
@Override
public List<AbstractParty> getParticipants() {
return Arrays.asList(partyA,partyB);
}
@Override
public PersistentState generateMappedObject(MappedSchema schema) {
if (schema instanceof SomeStateSchema) {
return new SomeStateSchema().new PersistentSomeState(uid.getId(), partyA.getName().toString(), partyB.getName().toString(), addresses);
} else {
throw new IllegalArgumentException("Unrecognised schema $schema");
}
}
@Override
public Iterable<MappedSchema> supportedSchemas() {
return ImmutableList.of(new SomeStateSchema());
}
@Override
public UniqueIdentifier getLinearId() {
return uid;
}
}
public class SomeStateSchema extends MappedSchema {
public SomeStateSchema() {
super(SomeStateSchema.class, 1, ImmutableList.of(PersistentSomeState.class));
}
@Entity
@Table(name = "records")
public class PersistentSomeState extends PersistentState{
@Column(name = "uid")
private final UUID uId;
@Column(name = "partyA")
private final String partyA;
@Column(name = "partyB")
private final String partyB;
@ElementCollection
private final List<Address> addresses;
public PersistentSomeState(UUID uId, String partyA, String partyB, List<Address> addresses) {
super();
this.uId = uId;
this.partyA = partyA;
this.partyB = partyB;
this.addresses = addresses;
}
public UUID getuId() {
return uId;
}
public String getPartyA() {
return partyA;
}
public String getPartyB() {
return partyB;
}
public List<Address> getAddresses() {
return addresses;
}
}
}
@CordaSerializable
public class Address {
public final String street;
public final int pincode;
public Address(String street, int pincode) {
super();
this.street = street;
this.pincode = pincode;
}
public String getStreet() {
return street;
}
public int getPincode() {
return pincode;
}
}
从控制器我打电话:
@GET
@Path("msas")
@Produces(MediaType.APPLICATION_JSON)
public List<StateAndRef<SomeState>> getMSAs() {
return rpcOps.vaultQuery(SomeState.class).getStates();
}
FLOW与IOU示例相同。
public SignedTransaction call() throws FlowException {
// Obtain a reference to the notary we want to use.
final Party notary = getServiceHub().getNetworkMapCache().getNotaryIdentities().get(0);
Set<PublicKey> set= getServiceHub().getKeyManagementService().getKeys();
//val ourParties = ourKeys.map { serviceHub.identityService.partyFromKey(it) ?: throw IllegalStateException("Unable to resolve party from key") }
//
List<Party> parties= new ArrayList();
for (Iterator<PublicKey> it = set.iterator(); it.hasNext(); ) {
parties.add(getServiceHub().getIdentityService().partyFromKey(it.next()));
}
progressTracker.setCurrentStep(GENERATING_TRANSACTION);
// Generate an unsigned transaction.
SomeState someState = new SomeState(getServiceHub().getMyInfo().getLegalIdentities().get(0),otherParty,Arrays.asList(new Address("Yes Street",12532)));
final Command<SomeContract.Commands.Create> txCommand = new Command<>(new SomeContract.Commands.Create(),
someState.getParticipants().stream().map(AbstractParty::getOwningKey).collect(Collectors.toList()));
final TransactionBuilder txBuilder = new TransactionBuilder(notary).withItems(new StateAndContract(someState, MSAContract.MSA_CONTRACT_ID), txCommand);
// Stage 2.
progressTracker.setCurrentStep(VERIFYING_TRANSACTION);
// Verify that the transaction is valid.
txBuilder.verify(getServiceHub());
// Stage 3.
progressTracker.setCurrentStep(SIGNING_TRANSACTION);
// Sign the transaction.
final SignedTransaction partSignedTx = getServiceHub().signInitialTransaction(txBuilder);
FlowSession otherPartySession = initiateFlow(otherparty);
// Stage 4.
progressTracker.setCurrentStep(GATHERING_SIGS);
// Send the state to the counterparty, and receive it back with their signature.
final SignedTransaction fullySignedTx = subFlow(
new CollectSignaturesFlow(partSignedTx, Sets.newHashSet(otherPartySession), CollectSignaturesFlow.Companion.tracker()));
// Stage 5.
progressTracker.setCurrentStep(FINALISING_TRANSACTION);
// Notarise and record the transaction in both parties' vaults.
return subFlow(new FinalityFlow(fullySignedTx));
}
我终于找到了rootException:
Caused by: org.hibernate.MappingException: Could not determine type for: com.den.managment.state.Address, at table: SomeStateSchema$PersistentSomeState_addresses, for columns: [org.hibernate.mapping.Column(addresses)]
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:455)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:422)
at org.hibernate.mapping.Collection.validate(Collection.java:310)
at org.hibernate.boot.internal.MetadataImpl.validate(MetadataImpl.java:333)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
at net.corda.node.services.persistence.HibernateConfiguration.buildSessionFactory(HibernateConfiguration.kt:101)
at net.corda.node.services.persistence.HibernateConfiguration.makeSessionFactoryForSchemas(HibernateConfiguration.kt:74)
at net.corda.node.services.persistence.HibernateConfiguration.access$makeSessionFactoryForSchemas(HibernateConfiguration.kt:27)
at net.corda.node.services.persistence.HibernateConfiguration$sessionFactoryForSchemas$1.apply(HibernateConfiguration.kt:54)
at net.corda.node.services.persistence.HibernateConfiguration$sessionFactoryForSchemas$1.apply(HibernateConfiguration.kt:27)
at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(Unknown Source)
at net.corda.node.services.persistence.HibernateConfiguration.sessionFactoryForSchemas(HibernateConfiguration.kt:54)
at net.corda.node.services.persistence.HibernateConfiguration.sessionFactoryForSchema(HibernateConfiguration.kt:48)
at net.corda.node.services.schema.HibernateObserver.persistStateWithSchema(HibernateObserver.kt:41)
at net.corda.node.services.schema.HibernateObserver.persistState(HibernateObserver.kt:37)
at net.corda.node.services.schema.HibernateObserver.persist(HibernateObserver.kt:31)
at net.corda.node.services.schema.HibernateObserver.access$persist(HibernateObserver.kt:20)
at net.corda.node.services.schema.HibernateObserver$1.call(HibernateObserver.kt:27)
at net.corda.node.services.schema.HibernateObserver$1.call(HibernateObserver.kt:20)
at rx.internal.util.ActionSubscriber.onNext(ActionSubscriber.java:39)
at rx.observers.SafeSubscriber.onNext(SafeSubscriber.java:134)
... 42 more
答案 0 :(得分:0)
由于您的代码存在潜在问题,您的流程会引发各种异常。 Corda然后尝试将这些异常序列化,以通过RPC框架将它们发送回RPC客户端。由于这些类型不是通过RPC发送的白名单,因此在尝试时会出现Kryo异常。
换句话说,这些异常只是(基础代码throwijng AnnotationException
或MappingException
)的症状,而不是根本原因。
您是否可以发布显示Person
状态定义的代码以及您尝试从流中的Vault中检索它的方式?