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

Hyperledger事务执行报错:指定查询不存在问题求助

Hyperledger Fabric: "The specified query does not exist" Error When Invoking Transaction

Problem Context

I've defined a Cashier participant in my Hyperledger business network model:

namespace com.emastersapp
/** 
* Cashier participant identified by userId 
*/ 
participant Cashier identified by userId { 
  o String userId 
}

And created a query in queries.qry:

query getCashierByUserId { 
  description: "Get Cashier by UserId" 
  statement: SELECT com.emastersapp.Cashier WHERE (userId == _$userId) 
}

When calling this query in logic.js:

let results = await query('getCashierByUserId', { userId: resource.userId });

I get this error during transaction execution:

"Error trying invoke business network. Error: No valid responses from any peers.\nResponse from attempted peer comms was an error: Error: 2 UNKNOWN: error executing chaincode: transaction returned with failure: Error: The specified query does not exist"

Troubleshooting & Solutions

Let's break down the most common causes and fixes for this error:

  • Mismatched query name or namespace issues
    Double-check that the query name you're calling in logic.js (getCashierByUserId) exactly matches the name defined in queries.qry—this includes case sensitivity. Hyperledger doesn't ignore uppercase/lowercase differences here, so a typo like getcashierbyuserid will fail. Also confirm the namespace in the query statement (com.emastersapp.Cashier) matches your participant's namespace from the CTO file.

  • Query file not included in the business network archive (BNA)
    It's easy to forget to repackage your business network after updating queries.qry. If the query wasn't included in the BNA you deployed, the chaincode won't recognize it. Follow these steps to refresh your deployment:

    1. Stop the running network:
      composer network stop -n your-network-name -c admin@your-network-name
      
    2. Repackage the network:
      composer archive create -t dir -n .
      
    3. Reinstall the network:
      composer network install -c PeerAdmin@hlfv1 -a your-network@x.x.x.bna
      
    4. Restart the network:
      composer network start -n your-network-name -c PeerAdmin@hlfv1 -V x.x.x -A admin -S adminpw
      
    5. Import the updated admin card:
      composer card import -f admin@your-network-name.card
      

    Make sure queries.qry lives in the same directory as your model.cto and logic.js—this is where the packaging tool expects it to be.

  • Stale chaincode instance
    Sometimes Fabric caches old chaincode instances, so even after repackaging, the peer might still be using an outdated version without your new query. Try deleting the old chaincode container (via Docker commands) and restarting the network. Alternatively, use the upgrade command to force a refresh:

    composer network upgrade -n your-network-name -c PeerAdmin@hlfv1 -V x.x.x
    
  • Syntax errors in the query definition
    A hidden syntax mistake in queries.qry can prevent the query from being registered. Double-check:

    • The SELECT statement uses the correct namespace and participant name
    • The parameter syntax (_$userId) is correct (leading underscore + dollar sign)
    • No typos, missing parentheses, or invalid characters (like curly quotes instead of straight quotes)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 07:03:48