Reputation: 3832
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();
}
Upvotes: 0
Views: 292
Reputation: 3832
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.
Upvotes: 1
Reputation: 41676
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
Upvotes: 0