【问题标题】:Corda: InstantiationException when extending FungibleState in custom SchemaCorda:在自定义 Schema 中扩展 FungibleState 时出现 InstantiationException
【发布时间】:2018-03-01 18:16:43
【问题描述】:

此问题与此处发布的问题类似:Corda: error=org.hibernate.InstantiationException: No default constructor for entity

对于扩展 FungibleState 的自定义架构(如 API Vault Query documentation 中所述),我遇到了同样的错误:

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

【问题讨论】:

  • 您是否尝试过创建一个没有参数的默认构造函数,它将空字符串、零等传递给父构造函数。比如:constructor() : this("", "", "", "").

标签: jpa kotlin corda


【解决方案1】:

您需要在PersistentCustomState 的主体中添加一个默认构造函数。比如:

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

困难在于传递AbstractParty 参数的默认值。你可以使用类似的东西:

AnonymousParty(generateKeyPair().public)

【讨论】:

  • 添加一个默认的构造函数现在有效。我仍然认为这是一种解决方法,我认为kotlin-jpa 插件会为我处理这个问题(并且不需要能够使所有字段都为空)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-26
相关资源
最近更新 更多