我遇到了一个问题,请帮忙。 Corda Code基于M13。我的架构代码主要用于定义架构,参考你的样本。
object LegalContractSchemaV1 : MappedSchema(
schemaFamily = LegalContractSchema.javaClass,
version = 1,
mappedTypes = listOf(PersistentLegalContractState::class.java)) {
@Entity
@Table(name = "legal_contract_states")
class PersistentLegalContractState(
@Column(name = "contract_title`enter code here`")
var contractTitle: String,
@Column(name = "sender_name")
var senderName: String,
@Column(name = "recipient_name")
var recipientName: String,
@Column(name = "status")
var status: String) : PersistentState(){
// constructor(stateRef: StateRef) : this(stateRef.txhash.bytes.toHexString(), stateRef.index)
}
Corda Node错误日志。 E 12:53:45 [rpc-server-handler-pool-0] vault.HibernateVaultQueryImpl._queryBy - org.hibernate.InstantiationException:没有默认构造函数 实体: : com.legalcontract.schema.LegalContractSchemaV1 $ PersistentLegalContractState E 12:53:45 [rpc-server-handler-pool-0] messaging.ObservableContext.sendMessage - 无法发送消息, 踢客户。消息是 RpcReply(ID = RpcRequestId(toLong = 4982229886899153484), result = ErrorOr(value = null,error = org.hibernate.InstantiationException: 没有实体的默认构造函数:: com.legalcontract.schema.LegalContractSchemaV1 $ PersistentLegalContractState)) com.esotericsoftware.kryo.KryoException:类org.hibernate.InstantiationException未注释或在 白名单,所以不能用于序列化 序列化跟踪: 错误(net.corda.core.ErrorOr) at net.corda.core.serialization.CordaClassResolver.checkClass(CordaClassResolver.kt:65) 〜[金色核-0.13.0.jar:?] at net.corda.core.serialization.CordaClassResolver.getRegistration(CordaClassResolver.kt:35) 〜[金色核-0.13.0.jar:?] 在com.esotericsoftware.kryo.Kryo.getRegistration(Kryo.java:488) 〜[KRYO-4.0.0.jar:?] at net.corda.nodeapi.RPCKryo.getRegistration(RPCStructures.kt:74) 〜[金色节点-API-0.13.0.jar:?] at com.esotericsoftware.kryo.util.DefaultClassResolver.writeClass(DefaultClassResolver.java:97) 〜[KRYO-4.0.0.jar:?]
答案 0 :(得分:1)
您需要在PersistentLegalContractState的主体中添加默认构造函数。类似的东西:
constructor() : this("", "", "", "")
答案 1 :(得分:1)
kotlin-noarg插件为已使用选定注释注释的类生成默认构造函数。
为注释的@Entity申请Kotlin-jpa插件以生成默认的construtor。
将脚本添加到gradle文件
buildscript {
dependencies {
classpath "org.jetbrains.kotlin:kotlin-noarg:$kotlin_version"
}
}
apply plugin: "kotlin-jpa"
答案 2 :(得分:1)
我在安装kotlin-jpa插件后也遇到了同样的错误(org.hibernate.InstantiationException:没有实体的默认构造函数)。
解决方案是让我的自定义架构中的所有字段都可以为空,例如:
object LegalContractSchemaV1 : MappedSchema(
schemaFamily = LegalContractSchema.javaClass,
version = 1,
mappedTypes = listOf(PersistentLegalContractState::class.java)) {
@Entity
@Table(name = "legal_contract_states")
class PersistentLegalContractState(
@Column(name = "contract_title`enter code here`")
var contractTitle: String? = null,
@Column(name = "sender_name")
var senderName: String? = null,
@Column(name = "recipient_name")
var recipientName: String? = null,
@Column(name = "status")
var status: String? = null) : PersistentState()