首页 > 解决方案 > Corda 4.1:如何使用其嵌入对象中的字段查询 PersistentState?

问题描述

在我的代码contractId中属于PersistentDeal,这是一个嵌入的对象PersistentDealStatePersistentDealStateDealState从 扩展而来的模式ContractState

如何将查询参数作为查询参数提供DealStatecontractId

此查询条件不起作用

val result = builder {
        val criteria = DealSchemaV1.PersistentDealState::deal.equal(DealSchemaV1.PersistentDeal::tcmContractID.equal(contractId))
        val queryCriteria = QueryCriteria.VaultCustomQueryCriteria(expression = criteria, contractStateTypes = setOf(DealState::class.java),status = status)
        vaultService.queryBy<DealState>(queryCriteria)
    }

这是我的模型

@Entity
    @Table(name = "DealState",
            indexes = [Index(name = "contract_id_index", columnList = "contract_id")])
    class PersistentDealState(

            @Embedded
            var deal: PersistentDeal

            some other fields...

    ) : PersistentState()


    @Embeddable
    class PersistentDeal(

            @Column(name = "contract_id")
            var contractID: Long,

            some other fields...
    )

标签: corda

解决方案


当前无法使用VaultCustomQueryCriteria指定嵌入对象的可过滤条件。请通过我们的 GitHub 网站提出问题 ( https://github.com/corda/corda/issues ) 来请求这个。

当前可用的选项是使用 JDBC 会话: https ://docs.corda.net/head/api-persistence.html#jdbc-session

或 JPA 实体管理器(和 HQL): https ://docs.corda.net/head/api-persistence.html#jpa-support


推荐阅读