You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Corda 4.7中LinearStateQueryCriteria与QueryCriteria类型不兼容导致的编译错误求助

Solution for Vault Query Compilation Issues with LinearId

It sounds like you're hitting a common API version mismatch issue with Corda's vault query classes—let's break this down and fix it step by step.

Root Cause

Corda has adjusted the structure of its QueryCriteria classes across versions:

  • In older Corda versions (pre-4.5 roughly), LinearStateQueryCriteria was a top-level class directly under net.corda.core.node.services.vault.
  • In newer versions, LinearStateQueryCriteria was moved to be an inner class of QueryCriteria (so it's QueryCriteria.LinearStateQueryCriteria).

The confusion happens when the documentation you're referencing is for a different version than the one you're using, leading to mismatched class structures and method signatures.

Fix 1: Align Your Code with Corda Version

If you're using an older Corda version (pre-4.5):

Ensure you're importing the top-level LinearStateQueryCriteria and using it directly with queryBy() (making sure to specify your state class as the first parameter):

import net.corda.core.node.services.vault.LinearStateQueryCriteria;
import net.corda.core.node.services.vault.Vault;
import com.google.common.collect.ImmutableList;

// Your linear ID string
String linearId = "your-linear-id-here";

// Build query criteria
LinearStateQueryCriteria queryCriteria = new LinearStateQueryCriteria(
    null,
    ImmutableList.of(UUID.fromString(linearId))
);

// Execute query—don't forget to pass your state class!
Vault.Page<YourLinearState> results = getServiceHub().getVaultService().queryBy(YourLinearState.class, queryCriteria);

If you're using a newer Corda version (4.5+):

Use the inner QueryCriteria.LinearStateQueryCriteria class, again ensuring you specify your state class when calling queryBy():

import net.corda.core.node.services.vault.QueryCriteria;
import net.corda.core.node.services.vault.Vault;
import com.google.common.collect.ImmutableList;

// Your linear ID string
String linearId = "your-linear-id-here";

// Build query criteria using the inner class
QueryCriteria.LinearStateQueryCriteria queryCriteria = new QueryCriteria.LinearStateQueryCriteria(
    null,
    ImmutableList.of(UUID.fromString(linearId))
);

// Execute query with your state class
Vault.Page<YourLinearState> results = getServiceHub().getVaultService().queryBy(YourLinearState.class, queryCriteria);

Fix 2: Verify queryBy() Method Signature

The most common mistake here is forgetting to pass your linear state class as the first parameter to queryBy(). The method requires both the state type and the criteria—without the state class, the compiler won't resolve the correct overload, leading to the "cannot accept queryCriteria" error.

Additional Checks

  • Double-check your build.gradle file to confirm your Corda version matches the documentation you're using.
  • Ensure your imports don't mix old and new classes (e.g., don't import both net.corda.core.node.services.vault.LinearStateQueryCriteria and net.corda.core.node.services.vault.QueryCriteria if you're on a new version).

内容的提问来源于stack exchange,提问作者Sourabh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 12:39:09