7.3. Transactions

Any query that updates the graph will run in a transaction. An updating query will always either fully succeed, or not succeed at all.

Cypher will either create a new transaction or run inside an existing one:

This can be used to have multiple queries be committed as a single transaction:

  1. Open a transaction,
  2. run multiple updating Cypher queries,
  3. and commit all of them in one go.

Note that a query will hold the changes in memory until the whole query has finished executing. A large query will consequently need a JVM with lots of heap space.

For using transactions over the REST API, see Section 19.1, “Transactional HTTP endpoint”.

When using Neo4j embedded, remember all iterators returned from an execution result should be exhausted fully to ensure that resources bound to them will be properly closed. Resources include transactions started by the query, so failing to do so may, for example, lead to deadlocks or other weird behavior.