Question

I tried to use $transaction->isError() and $transaction->isClosed in neo4j transaction, but these functions failed to catch the error.

Below is my code, where I did the transaction roll-back after committing, which according to the documentation should produce an error and it should be handled by isClosed(), but it never handled the error rather produced the error.

code

require("vendor/autoload.php");
        use Everyman\Neo4j\Cypher\Query;
        $client = new Everyman\Neo4j\Client();

        $transaction = $client->beginTransaction();

        $queryA = new Query($client, 'CREATE (n:testing{id:189})');
        $result = $transaction->addStatements($queryA);
        $transaction->commit();
        $transaction->rollback(); // performing rollback after commit
if ($transaction->isClosed()) {
    echo "No more statements can be added!";
}

Error

Fatal error: Uncaught exception 'Everyman\Neo4j\Exception' with message 'Transaction is already closed' in C:\xampp\htdocs\feed\vendor\everyman\neo4jphp\lib\Everyman\Neo4j\Transaction.php on line 149

But actually this error should be handled by $transaction->isClosed(),but it didin't

Please help, thanks in advance

No correct solution

OTHER TIPS

You can't rollback after a commit. The commit closes the transaction, so attempting to rollback throws an error.

You don't need to rollback after the commit. Rolling back will automatically happen on the server if any of the added statements fails. You only need to call rollback if your application manually needs to rollback the transaction, which you should do before committing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top