18.7. Transaction events

Transaction event handlers can be registered to receive Neo4j Transaction events. Once it has been registered at a GraphDatabaseService instance it will receive events about what has happened in each transaction which is about to be committed. Handlers won’t get notified about transactions which haven’t performed any write operation or won’t be committed (either if Transaction#success() hasn’t been called or the transaction has been marked as failed Transaction#failure(). Right before a transaction is about to be committed the beforeCommit method is called with the entire diff of modifications made in the transaction. At this point the transaction is still running so changes can still be made. However there’s no guarantee that other handlers will see such changes since the order in which handlers are executed is undefined. This method can also throw an exception and will, in such a case, prevent the transaction from being committed (where a call to afterRollback will follow). If beforeCommit is successfully executed in all registered handlers the transaction will be committed and the afterCommit method will be called with the same transaction data as well as the object returned from beforeCommit. In afterCommit the transaction has been closed and so accessing data outside of what TransactionData covers requires a new transaction to be opened. TransactionEventHandler gets notified about transactions that has any change accessible via TransactionData so some indexing and schema changes will not be triggering these events.