Corda 4.1: How to make a query of PersistentState with a field in its embeded object?

Viewed 155

In my code contractId belongs to PersistentDeal, which is an embedded object of PersistentDealState. PersistentDealState is the schema for DealState which extends from ContractState.

How to get DealState giving contractId as a query parameter to the query cryteria?

This query criteria does not work

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

Here are my models

@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 Answers
Related