【问题标题】:neo4j-rest-graphdb not able to handle transactions with Neo4J 2.0.xneo4j-rest-graphdb 无法使用 Neo4J 2.0.x 处理事务
【发布时间】:2014-07-16 08:56:54
【问题描述】:

我正在使用 neo4j-rest-graphdb 2.0.1(2.0.3 目前不可用)来访问独立的 Neo4j Community 2.0.3 REST 服务器。 特别是,我希望能够使用 neo4j-rest-graphdb 将查询分组到事务中。 README 说:

在 1.8 中,它尝试收集 tx 中的所有操作作为 然后将在服务器上执行的批处理操作。

这意味着在该“tx”中检索到的结果 不是立即可用,但只有在您调用 tx.success 和 tx.finish

但是,下面的(最简单的)代码使用了一个事务

db = new RestGraphDatabase(<SOMEURL>, <SOMEUSER>, <SOMEPASSWORD>);
System.setProperty(Config.CONFIG_BATCH_TRANSACTION,"true");

Transaction tx = db.beginTx();

// line where exception is thrown    
ResourceIterable<Node> it = db.findNodesByLabelAndProperty(DynamicLabel.label(type), "@id", id);

Node result = Iterables.getOnlyElement(it);

tx.success();
tx.finish();
tx.close();

抛出一个

java.lang.IllegalStateException: received org.neo4j.rest.graphdb.RequestResult@5acc5fb1
    at org.neo4j.rest.graphdb.ExecutingRestAPI.toNodeIterableResult(ExecutingRestAPI.java:284)
    at org.neo4j.rest.graphdb.ExecutingRestAPI.getNodesByLabelAndProperty(ExecutingRestAPI.java:273)
    at org.neo4j.rest.graphdb.RestAPIFacade.getNodesByLabelAndProperty(RestAPIFacade.java:344)
    at org.neo4j.rest.graphdb.RestGraphDatabase.findNodesByLabelAndProperty(RestGraphDatabase.java:147)   
    at {the marked line in the above code}

调试得到 Neo4j DB 返回的 RequestResult 的字段具有以下值:

  • 状态:0
  • batchId:1
  • batchResult: true
  • 字符串:“”
  • 所有其他字段:null

当我设置System.setProperty(Config.CONFIG_BATCH_TRANSACTION,"false"); 而不是“true”时,不会引发异常,并且请求会以正确的内容正确返回,但不是在事务上下文中。 为什么会这样? 如何让 neo4j-rest-graphdb 的(基于批处理的)事务正常工作?

【问题讨论】:

    标签: java rest transactions neo4j


    【解决方案1】:

    我问了一个类似的问题here,看起来有问题的图书馆已经停产了。仅通过带有密码端点的 HTTP 支持事务。 Spring data Neo4j 似乎是要走的路。否则,您可以使用 JDBC 层 (Example project here)。我今天才知道这一点,我必须将整个项目的代码更改为现在使用 Spring。叹息。

    【讨论】:

      猜你喜欢
      • 2015-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-17
      • 1970-01-01
      • 1970-01-01
      • 2014-12-10
      相关资源
      最近更新 更多