문제

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

올바른 솔루션이 없습니다

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top