Corda 4.1:如何使用其嵌入对象中的字段进行PersistentState查询?

时间:2019-07-02 07:16:03

标签: corda

在我的代码中,contractId属于PersistentDeal,它是PersistentDealState的嵌入式对象。 PersistentDealStateDealState的架构,它从ContractState扩展。

如何获取DealState并赋予contractId作为查询条件的查询参数?

此查询条件不起作用

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...
    )

1 个答案:

答案 0 :(得分:2)

当前无法使用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