Corda:在自定义模式中扩展 FungibleState 时的实例化异常



此问题类似于此处发布的问题:Corda:error=org.hibernate.InstantiationException:实体没有默认构造函数

对于扩展 FungibleState 的自定义架构,我收到相同的错误(如 API 保管库查询文档中所述(:

object CustomSchemaV1 : MappedSchema(schemaFamily = CustomSchema.javaClass, version = 1, mappedTypes = listOf(PersistentCustomState::class.java))
{
@Entity
@Table(name = "custom_states", indexes = arrayOf(Index(name = "custom_field_idx", columnList = "custom_field")))
class PersistentCustomState(
    /** Custom attributes */
    @Column(name = "custom_field")
    var customField: String? = null,
    /** FungibleState parent attributes */
    @Transient
    val _participants: Set<AbstractParty>,
    @Transient
    val _owner: AbstractParty,
    @Transient
    val _quantity: Long,
    @Transient
    val _issuerParty: AbstractParty,
    @Transient
    val _issuerRef: OpaqueBytes
) : CommonSchemaV1.FungibleState(_participants?.toMutableSet(), _owner, _quantity, _issuerParty, _issuerRef.bytes)}

此处找到的示例架构:https://github.com/corda/corda/blob/master/finance/src/test/kotlin/net/corda/finance/schemas/SampleCashSchemaV2.kt

我安装了kotlin-jpa插件。使所有字段都可为空似乎解决了扩展PersistentState的模式的问题,但由于父字段数据类型FungibleState,这里不是一个选项。

Corda发布版本 = 2.0.0

您需要

将默认构造函数添加到PersistentCustomState的主体中。像这样:

constructor() : this(*first default value*, *second default value*, etc.)

困难在于传递AbstractParty参数的默认值。您可以使用以下内容:

AnonymousParty(generateKeyPair().public)

最新更新