Neo4j 2.2.2和错误的Cypher查询

时间:2015-06-09 06:54:17

标签: neo4j cypher spring-data-neo4j graph-databases

继续这个问题Neo4j how to delete nodes recursively from some start node

我已经转移到Neo4j 2.2.2并且现在遇到一个Cypher查询的问题,该查询在之前的Neo4j 2.1.7上工作正常

我使用的是Spring Data Neo4J:

@Query("MATCH (d:Decision) WHERE id(d) IN {decisionsIds} WITH d OPTIONAL MATCH (d)-[r]-(t) DELETE d, r WITH t, r OPTIONAL MATCH (t)-[r2:VOTED_ON|:CREATED_BY|:VOTED_FOR]-() WITH t, r2, r WHERE none(x in labels(t) WHERE x in ['User', 'Decision']) DELETE t, r2")
void deleteDecisions(@Param("decisionsIds") List<Long> decisionsIds);

错误是:

org.springframework.dao.InvalidDataAccessResourceUsageException: Error executing statement MATCH (d:Decision) WHERE id(d) IN {decisionsIds} WITH d OPTIONAL MATCH (d)-[r]-(t) DELETE d, r WITH t, r OPTIONAL MATCH (t)-[r2:VOTED_ON|:CREATED_BY|:VOTED_FOR]-() WITH t, r2, r WHERE none(x in labels(t) WHERE x in ['User', 'Decision']) DELETE t, r2; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: Error executing statement MATCH (d:Decision) WHERE id(d) IN {decisionsIds} WITH d OPTIONAL MATCH (d)-[r]-(t) DELETE d, r WITH t, r OPTIONAL MATCH (t)-[r2:VOTED_ON|:CREATED_BY|:VOTED_FOR]-() WITH t, r2, r WHERE none(x in labels(t) WHERE x in ['User', 'Decision']) DELETE t, r2; nested exception is org.neo4j.kernel.api.exceptions.EntityNotFoundException: Unable to load NODE with id 227.
    at org.springframework.data.neo4j.support.query.CypherQueryEngineImpl.query(CypherQueryEngineImpl.java:61)
    at org.springframework.data.neo4j.repository.query.GraphRepositoryQuery.dispatchQuery(GraphRepositoryQuery.java:108)
    at org.springframework.data.neo4j.repository.query.GraphRepositoryQuery$1.doWithGraph(GraphRepositoryQuery.java:90)
    at org.springframework.data.neo4j.support.Neo4jTemplate.doExecute(Neo4jTemplate.java:465)
    at org.springframework.data.neo4j.support.Neo4jTemplate.access$000(Neo4jTemplate.java:87)
    at org.springframework.data.neo4j.support.Neo4jTemplate$2.doInTransaction(Neo4jTemplate.java:479)
    at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
    at org.springframework.data.neo4j.support.Neo4jTemplate.exec(Neo4jTemplate.java:476)
    at org.springframework.data.neo4j.repository.query.GraphRepositoryQuery.execute(GraphRepositoryQuery.java:84)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:431)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:409)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)

什么可能是错的?

已更新

调试后我发现无法加载ID为227的NODE 227是子节点ID ..例如我有一个ChildNode(id = 201),带有一个ChildNode(id = 227)。我想删除所有孩子的ParentNode。这样我需要传递父节点和子节点的{decisionsIds} ID(按顺序[227,201] - child child,parent next),现在问题是Cypher查询无法删除子节点出现以下错误无法加载ID为227的NODE ..但为什么它在Neo4j 2.1.7中工作以及如何在Neo4j中修复它2.2.2

1 个答案:

答案 0 :(得分:1)

[编辑#2]

其他信息非常有用。问题可能是t可以是已删除的子节点。

尝试此查询,以确保初始删除后使用的t不是已删除的节点。

MATCH (d:Decision)
WHERE id(d) IN {decisionsIds}
OPTIONAL MATCH (d)-[r]-(t)
DELETE d, r
WITH t, r
WHERE NOT (id(t) IN {decisionsIds})
OPTIONAL MATCH (t)-[r2:VOTED_ON|:CREATED_BY|:VOTED_FOR]-()
WHERE r2 <> r
WITH t, r2
WHERE none(x in labels(t) WHERE x in ['User', 'Decision'])
DELETE t, r2;