Transactions 无法处理Neo4j的java rest绑定上的事务

Transactions 无法处理Neo4j的java rest绑定上的事务,transactions,neo4j,Transactions,Neo4j,我在项目中使用了Neo4j,但在处理事务时遇到了一个问题 当名称为Error时,它可以成功地将节点插入DB…,如果我关闭事务控件,它仍然工作 final RestAPI api = new RestAPIFacade("http://localhost:7474/db/data"); final RestCypherQueryEngine engine = new RestCypherQueryEngine(api); Transaction tx = api.beginTx(); try {

我在项目中使用了Neo4j,但在处理事务时遇到了一个问题

当名称为
Error
时,它可以成功地将节点插入DB…,如果我关闭
事务
控件,它仍然工作

final RestAPI api = new RestAPIFacade("http://localhost:7474/db/data");
final RestCypherQueryEngine engine = new RestCypherQueryEngine(api);

Transaction tx = api.beginTx();
try {
    String name = "Error";
    Map<String, Object> subMap = new HashMap<String, Object>();
    subMap.put("name", name);
    subMap.put("age", 17);
    Node node = api.createNode(subMap);
    Label label = DynamicLabel.label("Student");
    node.addLabel(label);

    if("Error".equals(name)) {
        tx.failure();
    }
    else {
        tx.success();
    }
} finally {
    tx.finish();
}
final RestAPI api=new RestAPIFacade(“http://localhost:7474/db/data");
最终RestCypherQueryEngine发动机=新RestCypherQueryEngine(api);
事务tx=api.beginTx();
试一试{
String name=“Error”;
Map subMap=newhashmap();
子映射put(“名称”,名称);
次贴图put(“年龄”,17岁);
Node Node=api.createNode(subMap);
标签标签=DynamicLabel.Label(“学生”);
node.addLabel(标签);
如果(“错误”。等于(名称)){
tx.故障();
}
否则{
成功();
}
}最后{
tx.finish();
}

REST上没有事务,只是每个http请求发送一次。存在通过批处理操作进行的伪发送,但您必须启用它

我更推荐使用JDBC驱动程序,它支持Neo4j 2.x的在线事务


我发现我必须将下面的参数设置为
true
,我可以控制交易

org.neo4j.rest.batch_transaction=true
但是neo4j rest绑定的事务有一个问题,您不能在事务中使用get-method/cypher。当您想要更新/添加/删除事务中的节点或关系时,只能放置方法/cypher