Neo4jClient 事务错误

Neo4jClient Transaction Error

当我尝试在不使用事务的情况下更新 Neo4JClient 中的现有节点时,事务对 ID 和名称具有唯一约束 属性,我收到此异常:

CypherExecutionException: Node 6 already exists with label User and property "Name"=[Mike]

但是当我尝试更新事务中的节点时,我收到此异常:

Received an unexpected HTTP status when executing the request.

The response status was: 404 Not Found

The response from Neo4j (which might include useful detail!) was: {"results":[],"errors":[{"code":"Neo.ClientError.Transaction.UnknownId","message":"Unrecognized transaction id. Transaction may have timed out and been rolled back."}]}

我的代码是这样的:

using (var transaction = client.BeginTransaction())
{
    client.Cypher
        .Merge("(user:User { Id: {id}})")
        .OnCreate().Set("user = {user}")
        .OnMatch().Set("user = {user}")
        .WithParams(new { id = user.Id, user = user })
        .ExecuteWithoutResults();

    transaction.Commit();
}

我的问题是:有没有办法在使用事务时获取实际错误,就像我在不使用事务时得到的一样?

谢谢

编辑 1:

NULL Id 似乎没有被正确处理。深入研究后,我设法找出了实际错误。第一个例外是:

errors = {[
  {
    "code": "Neo.ClientError.Statement.InvalidSemantics",
    "message": "Cannot merge node using null property value for Id"
  }
]}

此异常的堆栈跟踪是:

at Neo4jClient.Serialization.CypherJsonDeserializer1.GetRootResultInTransaction(JObject root) in [PATH_HIIDEN]\Neo4jClient\Serialization\CypherJsonDeserializer.cs:line 316 at Neo4jClient.Serialization.CypherJsonDeserializer1.CheckForErrorsInTransactionResponse(String content) in [PATH_HIIDEN]\Neo4jClient\Serialization\CypherJsonDeserializer.cs:line 291 at Neo4jClient.GraphClient.<>c__DisplayClass84_01.<PrepareCypherRequest>b__0(Task1 responseTask) in [PATH_HIIDEN]\Neo4jClient\GraphClient.cs:line 933 at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke() at System.Threading.Tasks.Task.Execute()

然后出现 404 NOT Found 错误的异常。为此,堆栈跟踪是:

at Neo4jClient.Execution.HttpResponseMessageExtensions.EnsureExpectedStatusCode(HttpResponseMessage response, String commandDescription, HttpStatusCode[] expectedStatusCodes) in [PATH_HIIDEN]\Neo4jClient\Execution\HttpResponseMessageExtensions.cs:line 41 at Neo4jClient.Execution.HttpResponseMessageExtensions.EnsureExpectedStatusCode(HttpResponseMessage response, HttpStatusCode[] expectedStatusCodes) in [PATH_HIIDEN]\Neo4jClient\Execution\HttpResponseMessageExtensions.cs:line 14 at Neo4jClient.Execution.ResponseBuilder.<>c__DisplayClass21_0.b__0(Task1 requestTask) in [PATH_HIIDEN]\Neo4jClient\Execution\ResponseBuilder.cs:line 127 at System.Threading.Tasks.ContinuationResultTaskFromResultTask2.InnerInvoke() at System.Threading.Tasks.Task.Execute()

能否在下一个版本中修复此错误?

编辑 2

using (var transaction = client.BeginTransaction())
{
    manifest.Users = client.Cypher
        .Merge("(n:User { Id: '8be0b8fd-c433-44d3-a7e2-3f0d1a03fefa'}) " +
            "ON CREATE " +
            "SET n = { " +
                "Id: '8be0b8fd-c433-44d3-a7e2-3f0d1a03fefa', " +
                "UserName: 'test.user', " +
                "Name: 'Test User', " +
                "Active: true " +
            "} " +
            "ON MATCH " +
            "SET n = { " +
                "Id: '8be0b8fd-c433-44d3-a7e2-3f0d1a03fefa', " +
                "UserName: 'test.user', " +
                "Name: 'Test User', " +
                "Active: true " + 
            "}")
        .Return(n => n.As<User>())
        .Results
        .ToList();
    transaction.Commit();
}

意思是流利 Api 是导致错误的原因。

所以问题是在 Neo4j 2.2.6 中引入了一项更改,其中任何 ClientError(违反约束等)都会导致服务器上的事务自动回滚。

Neo4jClient 已经执行了错误自动回滚,并继续这样做。在 2.2.6 中,这会导致 404 错误,因为事务不再存在(以前的版本没问题)。

所以,我已经修复并发布了更新的 Nuget 包,因此 Neo4jClient1.1.0.12 版本现在会给你正确的响应。