Database Reference
In-Depth Information
Cypher and transactions
When running Cypher from a command line or web interface, each query execution is
wrappedinasingletransaction.Youdon'thavetoworryaboutstartingorfinishingtransac-
tions or dealing with their failure—everything will be taken care of by the Neo4j engine. If
the query succeeds, the transaction will automatically commit. If the query fails, the trans-
action will be rolled back.
Inanapplicationcontext,Cypherquerieswillexecutewiththeexistingtransactioncontext.
If you create a transaction programmatically, you can use multiple queries within the same
transaction and commit or roll back everything at the end.
Because we're using Neo4j Shell or the Web Admin Console to run the Cypher examples
throughout this chapter, each query is automatically wrapped in a single transaction, so no
additional setup is necessary.
For in-depth information about Neo4j transactions, read chapter 7 on Neo4j transactions.
So far you've created a node with some properties and a relationship. But you could have
done all that in a single command, as the following snippet illustrates:
In this example, you fixed an existing john node . In the create clause, you spe-
cified the pattern from john , via a non-existent IS_FRIEND_OF relationship, to a non-
existent node grace , with the same properties as before . Cypher is smart enough to
recognize which nodes and relationships are fixed ( john from the start clause), and
which are new and should be created in the database (the IS_FRIEND_OF relationship
Search WWH ::




Custom Search