Neo4j Transaction

Transaction Encapsulation Requirements

All write operations on Neo4j database must be explicitly encapsulated in a transaction:

try (Transaction tx = graphDb.beginTx()) {
    // Database operation code
    tx.success();
}

Isolation Level

Default isolation level is READ_COMMITTED.

Deadlock Handling

Neo4j implements an intelligent deadlock prevention system that automatically throws DeadlockDetectedException.

Neo4j Index

Create Single Index

CREATE INDEX ON :Person(name)

Create Composite Index

CREATE INDEX ON :Person(age, gender)

Full-text Index

CALL db.index.fulltext.createNodeIndex(
  "index_name",
  ["Label1", "Label2"],
  ["property1", "property2"]
)

View and Delete Index

SHOW INDEXES
DROP INDEX ON :Person(name)

Neo4j Constraint

Uniqueness Constraint

CREATE CONSTRAINT unique_user_email
FOR (user:User) REQUIRE user.email IS UNIQUE

View Constraints

call db.constraints