我创建了一个Neo4j扩展。它包含我自己的TransactionEventHandler
。有时,beforeCommit()
方法的执行会导致UniquePropertyConstraintViolationKernelException
。没关系。但在服务器端,我收到ResultProcessingException
。这个异常看起来过于笼统。我认为,它可能会因为很多原因而抛出,不仅仅是在违反约束的情况下。所以,我的问题是我应该如何处理服务器端的约束违规?我使用SDN4。
编辑1:所有neo4j-ogm- *版本都更新为2.0.3
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-core</artifactId>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-http-driver</artifactId>
<version>2.0.3</version>
</dependency>
</dependencies>
</dependencyManagement>
答案 0 :(得分:2)
如果您使用SDN 4.0,这是一个已知问题,抛出的异常太宽。
在SDN 4.1.1中,我们引入了一个包含底层Neo4j错误代码的CypherException,当Cypher执行失败时,这会在所有3个驱动程序中统一抛出。如果你正在使用SDN 4.1.1并且你没有收到此例外,我们可能会错过代码的某些区域 - 请raise a github issue详细了解如何重现这一点
更新:
意识到SDN 4.1.1依赖于OGM 2.0.1,它产生了CypherException,但没有包含原因。请将neo4j-ogm-core和任何驱动程序版本覆盖为2.0.3
CypherException.getCode()
应生成Neo.ClientError.Schema.ConstraintViolation
。请注意,如果使用嵌入式驱动程序,则会包装基础异常。但是通过HTTP驱动程序,不会收到此信息,因此您只会在CypherException中收到以下内容:
code: Neo.ClientError.Schema.ConstraintViolation
description: Node 7 already exists with label User and property "name"=[luanne]