I have a Neo4j Database with some graph created. I want to execute a set of cypher statements against this database from a java micro service. Two transactions are required to write data. If second transaction is failing, I want to revert the first transaction. There seems no way to revert a previously committed transaction.
In order to solve this problem , I am thinking to load the current session to am Embedded Neo4j database and execute both transactions. Only if both transactions are successful, I will try to run against the real database.
Is it possible to create Embedded Database from a session( so that the graph in session is replicated to Embedded Server). Is there any other way to solve this problem?
The first transaction is a schema changing transaction(Delete/Create Constraints) . We cannot combine schema changing transaction with other transactions. So I cannot combine them. Do you think, I should reapply schema changes in case the second transaction fail? Is that only solution? Any way to temporary run multiple transactions and verify the result?
Is there really a need to undo a schema changing transaction, at least if it's for creation? There's usually no harm in keeping a constraint or index once created, even if a a followup transaction that is meant to use them isn't able to finish successfully. In 4.x you can use
IF NOT EXISTS to ensure you can re-execute a schema command and it will succeed even if the constraint or index already exists, if that was part of your trouble with wanting to rollback.
As far as rollback, we only have it at a single transaction level.