【问题标题】:Neo4j Java driver 4.4 IN clauseNeo4j Java 驱动程序 4.4 IN 子句
【发布时间】:2023-02-15 11:15:38
【问题描述】:

我想运行以下查询,但是出现了一些错误。我在 neo4j 工作区上测试了我的查询,它正在运行。我找不到使用 IN 查询的 Java 驱动程序的任何源代码,所以我不确定我的代码有什么问题。我正在使用 Neo4j Java 驱动程序 4.4。

ArrayList<String> changedMethods = ...

Query query = new Query(
                "MATCH (changedFunction: Function) WHERE changedFunction.signature IN $changedMethods \n" +
                "MATCH (affectedFunction: Function)-[:CALLS]->(changedFunction) \n" +
                "RETURN affectedFunction.functionName", parameters("changedMethods", changedMethods));

try (Session session = driver.session(SessionConfig.forDatabase("neo4j"))) {
     List<Record> a = session.readTransaction(tx -> tx.run(query)).list();
     System.out.println(a.get(0).toString());
}

运行此代码后,出现以下错误

org.neo4j.driver.exceptions.ResultConsumedException: Cannot access records on this result any more as the result has already been consumed or the query runner where the result is created has already been closed.

【问题讨论】:

  • 我不认为这与 IN 查询有任何关系。你不需要阅读list()的结果吗?里面你的交易,不在外面?
  • @knittl 是的,你是对的。在事务中移动 list() 解决了这个问题。谢谢。

标签: java neo4j neo4j-java-api


【解决方案1】:

您无法在交易之外读取交易的结果。您必须从交易中读取结果:

try (Session session = driver.session(SessionConfig.forDatabase("neo4j"))) {
     List<Record> a = session.readTransaction(tx -> tx.run(query).list());
     System.out.println(a.get(0).toString());
}

或者

try (Session session = driver.session(SessionConfig.forDatabase("neo4j"))) {
    session.readTransaction(tx -> {
            List<Record> a = tx.run(query).list();
            System.out.println(a.get(0).toString());
    });
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-10
    • 2018-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-01
    • 1970-01-01
    相关资源
    最近更新 更多