Database Reference
In-Depth Information
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.
The following listing shows code that first reads a node representing a person, then at-
tempts to set an age property on it.
Listing 7.1. Attempting to update without a transaction
Note
Examples in this chapter deliberately assume a very simple data model that consists of two
nodes, John and Bob, representing two people with age properties set on them. This data
model will be sufficient to demonstrate the transactional behavior of Neo4j.
When executing this code with a pre-2.0 version of Neo4j, line will pass but line
will result in a NotInTransactionException . This is because mutating operations
in Neo4j 1.X required a transaction, while read-only ones did not.In Neo4j 2.0 and later
versions, both
and
will fail with a NotInTransactionException .
7.1.1. Adding in a transaction
The following listing shows the code from listing 7.1 but with transaction management ad-
ded. For the rest of this chapter, we'll assume the transactional style and requirements of
Neo4j 2.0.
 
Search WWH ::




Custom Search