【发布时间】: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