質問

I use Java REST binding of Neo4j on my project, but I face a problem on handling transactions.

When the name is Error, it can success insert node into DB..., event if I take off Transaction control, it still works.

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();
}
役に立ちましたか?

解決

I found I have to set below parameter to be true, and I could control the transaction!

org.neo4j.rest.batch_transaction=true

But there is an issue about the transaction of neo4j-rest-binding, you could not use get method/cypher in transaction. You could only put method/cypher when to want to update/add/delete nodes or relationships in transaction.

他のヒント

There are no transactions over REST, it just is one TX per http request. There is a fake tx by batching operations but you have to enable it.

I'd rather recommend using the JDBC driver which supports transactions over the wire for Neo4j 2.x

https://github.com/neo4j-contrib/neo4j-jdbc/tree/2.0

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top