neo4j 事务不回滚 [英] neo4j transaction not rolling back

查看:61
本文介绍了neo4j 事务不回滚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 java 中使用 neo4j 2.1.7.

I am using neo4j 2.1.7 with java.

    try(Transaction transaction = this.graphDatabaseService.beginTx())
    {
        Node user = this.graphDatabaseService.createNode();
        user.setProperty("userId", userId);
        transaction.failure();
    }

所以我正在获取 GraphDatabaseService 的对象并创建一个新事务并将其标记为回滚.根据他们的javadocs:

So I am getting the object of GraphDatabaseService and creating a new transaction and marking it to rollback. According to their javadocs:

void failure()

将此事务标记为失败,这意味着它将调用 close() 时无条件回滚.一旦这方法已被调用,是否调用success()无关紧要之后——事务仍将回滚.

Marks this transaction as failed, which means that it will unconditionally be rolled back when close() is called. Once this method has been invoked, it doesn't matter if success() is invoked afterwards -- the transaction will still be rolled back.

但是我看到无论如何都会创建节点.我试过抛出异常.我也试过根本不调用transaction.success().我仍然看到更改被提交而不是回滚.我不确定这种行为,并希望得到解释.谢谢.

But I see that the node gets created no matter what. I tried throwing an exception. I also tried not calling transaction.success() at all. Still I see that the changes get committed and not rolled back. I am not sure of this behaviour and would like an explanation. Thanks.

如果您必须知道,我正在尝试使用嵌套事务构建 commit() 函数,这样如果内部事务中的任何操作失败,父事务也必须失败.然而,在这个过程中我发现无论我做什么,事务都在被提交.

If you must know, I am trying to build a commit() function with nested transactions such that if any operation fail within the inner transactions, the parent transaction must fail too. However, in the process I found that no matter what I do, the transactions are getting committed.

更新 1:

neo4j 的嵌入式版本工作正常.其余版本导致了这个问题.我正在使用这个包休息:

The embedded version of neo4j works fine. The rest version is causing this trouble. I am using this package for rest:

<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-rest-graphdb</artifactId>
    <version>2.0.1</version>
</dependency>

推荐答案

没有基于 REST 的事务,至少对于旧版本没有.

No transactions over REST, at least not for that old version.

只有新的 Cypher Endpoint 通过 HTTP 进行交易.

There are only transactions over HTTP with the new Cypher Endpoint.

该库已停产,我建议您使用例如JDBC 驱动程序或 Spring Data REST 附带的新实现.

That library is discontinued, I recommend that you use e.g. the JDBC driver or the new implementation that comes with Spring Data REST.

这篇关于neo4j 事务不回滚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆