实践Neo4j之八事务

Transaction

Neo4j 2.0 requires a transaction to be initiated for any read or write operation on a graph object including nodes, relationships, schemas, and indexes. Note that in previous versions of Neo4j, there was no such requirement for read operations.

1
2
3
4
5
6
7
try (Transaction tx = graphDb.beginTx()) {
	user1 = this.graphDb.createNode();
    logger.info("created user:" + user1.getId());
    tx.success();
  	//如果失败则
    //tx.failure();
}

or

1
2
3
4
5
6
7
8
9
10
11
Transaction tx = graphDb.beginTx();
    try {
        user1 = this.graphDb.createNode();
        logger.info("created user:" + user1.getId());
      	//成功
        tx.success();
      	//如果失败则
      	//tx.failure();
    } finally {
      	tx.finish();
}