我在 PHP 5.6.24 上使用 graphaware/neo4j-php-client 4.5.1 和 Neo4j 3.0.4。
我不明白如何找出交易是否失败。
例如,我尝试删除仍然有关系的节点。如果我在这个简单的查询中运行 DELETE:
$client->run
(
'MATCH (node { name: {name} }) DELETE node',
[ 'name' => 'Fred' ]
);
......我得到了这个异常,这是我所期望的行为:
[GraphAware\Neo4j\Client\Exception\Neo4jException]
org.neo4j.kernel.api.exceptions.ConstraintViolationTransactionFailureException:
Cannot delete node<31>, because it still has relationships.
To delete this node, you must first delete its relationships.
但是当我将相同的查询包装在事务中时:
$transaction = $client->transaction();
$transaction->push
(
'MATCH (node { name: {name} }) DELETE node',
[ 'name' => 'Fred' ]
);
$results = $transaction->commit();
foreach ($results as $result)
{
$summary = $result->summarize();
$stats = $summary->updateStatistics();
printf("Nodes deleted: %d\n", $stats->nodesDeleted());
}
printf("Transaction status: %s\n", $transaction->status());
... Neo4j 不会删除节点,但我看到了这个(暗示成功)而不是异常:
Nodes deleted: 1
Transaction status: COMMITED
我错过了什么,还是这是一个错误?提前致谢!