Search code examples
neo4jneo4j-java-api

Any reason to call `tx.success()` on a Neo4j read-only transaction?


I'm using the Java API to improve performance of what was once an expensive Cypher query. I was refactoring just now and noticed that I'm calling tx.success(), even though I'm not changing any data. Is there any performance downside to marking a transaction successful when nothing has changed or does it not matter since it knows that there's nothing to actually commit?


Solution

  • I did dive into the Java Api too and ran immediately in a case where this was needed.

    If you use nested transactions and have outer code calling your read operation that is not doing tx.success, then when the outer transaction will try to commit(tx.success()), your inner transaction(your read) will mark the tx as not having completed successfully) and the database will raise an exception.