【问题标题】:How to create persisting hierarchical structure with states如何创建具有状态的持久层次结构
【发布时间】:2019-10-27 18:41:16
【问题描述】:

我一直在尝试使用https://docs.corda.net/releases/release-V4.0/api-persistence.html?highlight=generatemappedobject#persisting-hierarchical-data 作为指导来创建一个持久的分层状态结构。

我的结构如下。我有一个可以有 0..* ServiceDataStates 的 ServiceState。将来 ServiceDataState 也可以有 0..* usePurposeStates 但现在可以忽略。

您可以看到我当前的架构和状态。我的corda版本是3.3

object ServiceSchema

@CordaSerializable
object ServiceSchemaV1 : MappedSchema(
    schemaFamily = ServiceSchema.javaClass,
    version = 1,
    mappedTypes = listOf(ServiceSchemaV1.PersistentServiceState::class.java,
        ServiceDataSchemaV1.PersistentServiceDataState::class.java)) {

    @Entity
    @Table(name = "service_state")
    class PersistentServiceState (

        @Column(name = "linear_id", unique = true, nullable = false)
        var linearId: UUID,

        @Column(name = "account_operator", nullable = false)
        var accountOoperator: String,

        @Column(name = "service_provider", nullable = false)
        var serviceProvider: String,

        @Column(name = "service_name", nullable = false)
        var serviceName: String,

        @Column(name = "service_description", nullable = false)
        var serviceDescription: String,

        @Column(name = "date_created", nullable = false)
        var dateCreated: LocalDate,

        @JoinColumns(
            JoinColumn(name = "transaction_id", referencedColumnName = "transaction_id"),
            JoinColumn(name = "output_index", referencedColumnName = "output_index"))
        var serviceDataStates: MutableList<ServiceDataState>?,

        @Column(name = "service_partner_name", nullable = true)
        var servicePartners: String?

    ) : PersistentState() {
        constructor() : this(
            UUID.randomUUID(),
            "",
            "",
            "",
            "",
            LocalDate.now(),
            mutableListOf(),
            ""
        )
    }
}
object ServiceDataSchema

@CordaSerializable
object ServiceDataSchemaV1: MappedSchema(
    schemaFamily = ServiceDataSchema.javaClass,
    version = 1,
    mappedTypes = listOf(ServiceDataSchemaV1.PersistentServiceDataState::class.java,
        ServiceSchemaV1.PersistentServiceState::class.java,
        UsePurposeSchemaV1.PersistentUsePurposeState::class.java)) {

    @Entity
    @Table(name = "servicedata_state")
    class PersistentServiceDataState(

        @Column(name = "linearid", unique = true, nullable = false)
        var linearId: UUID,

        @Column(name = "name", nullable = false)
        var name: String,

        @Column(name = "type", nullable = false)
        var type: String,

        @Column(name = "usepurposes")
        var usePurposes: UUID,

        @Column(name = "api_schema", nullable = false)
        var apiSchema: String,

        @Column(name = "api_transfer_terms", nullable = false)
        var apiTransferTerms: String,

        @Column(name = "servicedata_party_name", nullable = true)
        var parties: String?,

        @ManyToOne(targetEntity = ServiceSchemaV1.PersistentServiceState::class)
        var persistentServiceState: ServiceState?

    ) : PersistentState() {
        constructor() : this(
            UUID.randomUUID(),
            "",
            "",
            UUID.randomUUID(),
            "",
            "",
            "",
            null
        )
    }

}
data class ServiceState(
    val accountOperator: Party,
    val serviceProvider: Party,
    val serviceName: String,
    val serviceDescription: String,
    val dateCreated: LocalDate,
    val serviceDataStates: MutableList<ServiceDataState>,
    val servicePartners: MutableList<Party>,
    override val linearId: UniqueIdentifier = UniqueIdentifier()
) : LinearState, QueryableState {

    override fun supportedSchemas(): Iterable<MappedSchema> = listOf(ServiceSchemaV1)

    override val participants get() =
        listOf(accountOperator, serviceProvider)

    override fun generateMappedObject(schema: MappedSchema): PersistentState {
        return when (schema) {
            is ServiceSchemaV1 -> ServiceSchemaV1.PersistentServiceState(
                this.linearId.id,
                this.accountOperator.name.toString(),
                this.serviceProvider.name.toString(),
                this.serviceName,
                this.serviceDescription,
                this.dateCreated,
                this.serviceDataStates,
                this.servicePartners[0]?.name.toString()
            )
            else -> throw IllegalArgumentException("Unrecognised schema $schema")
        }
    }

    fun serviceCopyWithTodaysDate() = copy(dateCreated = LocalDate.now())

    fun addServiceData(
        serviceDataList: MutableList<ServiceDataState>,
        id: UniqueIdentifier
    ) = copy(
        serviceDataStates = serviceDataList,
        linearId = id
    )

    fun addPartners(servicePartners: MutableList<Party>, id: UniqueIdentifier) = copy(
            servicePartners = servicePartners,
            linearId = id
    )
}
data class ServiceDataState(
    override val linearId: UniqueIdentifier = UniqueIdentifier(),
    val name: String,
    val type: String,
    val usePurposes: MutableList<UniqueIdentifier>,
    val service: ServiceState,
    val apiSchema: String,
    val apiTransferTerms: String,
    val parties: MutableList<Party>
) : LinearState, QueryableState {

    override val participants: List<Party> get() =
        parties

    override fun generateMappedObject(schema: MappedSchema): PersistentState {
        return when (schema) {
            is ServiceDataSchemaV1 -> ServiceDataSchemaV1.PersistentServiceDataState(
                this.linearId.id,
                this.name,
                this.type,
                this.usePurposes[0]?.id,
                this.apiSchema,
                this.apiTransferTerms,
                this.parties[0]?.name.toString(),
                this.service
            )
            else -> throw IllegalArgumentException("Unrecognised schema $schema")
        }
    }

    override fun supportedSchemas(): Iterable<MappedSchema> = listOf(ServiceDataSchemaV1)

我不知道我错过了什么。当我启动我的节点时,我得到以下堆栈跟踪

org.hibernate.MappingException: Could not determine type for: java.util.List, at table: service_state, for columns: [org.hibernate.mapping.Column(serviceDataStates)]
    at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:455) ~[hibernate-core-5.2.6.Final.jar:5.2.6.Final]
    at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:422) ~[hibernate-core-5.2.6.Final.jar:5.2.6.Final]
    at org.hibernate.mapping.Property.isValid(Property.java:226) ~[hibernate-core-5.2.6.Final.jar:5.2.6.Final]
    at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:597) ~[hibernate-core-5.2.6.Final.jar:5.2.6.Final]

【问题讨论】:

  • 您是否看过其他 stackoverflow 帖子,因为这看起来像是一个休眠问题。 stackoverflow.com/questions/3774198/…stackoverflow.com/questions/47236527/…
  • 谢谢,我检查了这些链接,在我看来,我在这两种模式中都坚持基于字段的访问。我还更新了我的代码(在两个模式中将各方类型更改为字符串),但我仍然收到相同的错误:(

标签: hibernate kotlin corda


【解决方案1】:

这绝对看起来像一个休眠问题,特别是您必须添加一些注释来清除问题的问题。

如果是针对您的特定问题的列表,可能是这样的?

@Column
@ElementCollection(targetClass=Integer.class)
private List<Integer> countries;

看看这些帖子,他们可能会有所帮助。

org.hibernate.MappingException: Could not determine type for: java.util.Set

org.hibernate.MappingException: Could not determine type for: java.util.List, at table: College, for columns: [org.hibernate.mapping.Column(students)]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多