0

我使用 py2neo 将数据转储到 Neo4j 数据库中。

有了这个

batch = neo4j.WriteBatch(graph_db)
batch.create(node(name="Alice"))
batch.create(node(name="Bob"))
batch.create(rel(0, "KNOWS", 1))
results = batch.submit()

我可以使用同一批次中的新节点创建关系。

但是,如果我尝试与在批处理之前已经创建的节点创建关系,如下所示:

n = graph_db.create({"name": "Smith"})
batch = neo4j.WriteBatch(graph_db)
batch.create(node(name="Alice"))
batch.create(rel(0, "KNOWS", n))
results = batch.submit()

它失败*。将如何继续在批次中创建与先前创建的节点有关系的节点?

使用 py2neo 1.5.1 和 Neo4j 1.9.2

谢谢

  • 错误信息 :

SystemError: {u'stacktrace': [u'org.neo4j.server.rest.batch.NonStreamingBatchOperations.invoke(NonStreamingBatchOperations.java:63)', u'org.neo4j.server.rest.batch.BatchOperations.performRequest(BatchOperations .java:188)', u'org.neo4j.server.rest.batch.BatchOperations.parseAndPerform(BatchOperations.java:159)', u'org.neo4j.server.rest.batch.NonStreamingBatchOperations.performBatchJobs(NonStreamingBatchOperations.java :48)', u'org.neo4j.server.rest.web.BatchOperationService.batchProcess(BatchOperationService.java:117)', u'org.neo4j.server.rest.web.BatchOperationService.performBatchOperations(BatchOperationService.java:72 )', u'java.lang.reflect.Method.invoke(Method.java:606)', u'org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112)'], u'信息':u'{\n "message" : "对于输入字符串: \"5078\')]}\"",\n "exception" : "BadInputException",\n "fullname" : "org.neo4j.server.rest .repr.BadInputException",\n "stacktrace" : [ "org.neo4j.server.rest.web.RestfulGraphDatabase.extractNodeId(RestfulGraphDatabase.java:171)", "org.neo4j.server.rest.web.RestfulGraphDatabase.createRelationship (RestfulGraphDatabase.java:410)"、"java.lang.reflect.Method.invoke(Method.java:606)"、"org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112)" , "org.neo4j.server.web.Jetty6WebServer.invokeDirectly(Jetty6WebServer.java:302)", "org.neo4j.server.rest.batch.NonStreamingBatchOperations.invoke(NonStreamingBatchOperations.java:55)", "org.neo4j.server.rest.batch.BatchOperations.performRequest(BatchOperations.java:188)”、“org.neo4j.server.rest.batch.BatchOperations.parseAndPerform(BatchOperations.java:159)”、“org.neo4j.server.rest. batch.NonStreamingBatchOperations.performBatchJobs(NonStreamingBatchOperations.java:48)”、“org.neo4j.server.rest.web.BatchOperationService.batchProcess(BatchOperationService.java:117)”、“org.neo4j.server.rest.web.BatchOperationService。 performBatchOperations(BatchOperationService.java:72)”、“java.lang.reflect.Method.invoke(Method.java:606)”、“org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112) " ],\n "cause" : {\n "message" : "对于输入字符串:\"5078\')]}\"",\n "exception" : "NumberFormatException",\n "stacktrace" : [ "java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)", "java.lang.Long.parseLong(Long.java:441)", "java.lang.Long.parseLong( Long.java:483)”、“org.neo4j.server.rest.web.RestfulGraphDatabase.extractNodeId(RestfulGraphDatabase.java:167)”、“org.neo4j.server.rest.web.RestfulGraphDatabase.createRelationship(RestfulGraphDatabase.java: 410)”、“java.lang.reflect.Method.invoke(Method.java:606)”、“org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112)”、“org.neo4j .server.web.Jetty6WebServer.invokeDirectly(Jetty6WebServer.java:302)”,“org.neo4j.server.rest.batch.NonStreamingBatchOperations.invoke(NonStreamingBatchOperations.java:55)”,“org.neo4j.server.rest.batch .批处理操作。performRequest(BatchOperations.java:188)”、“org.neo4j.server.rest.batch.BatchOperations.parseAndPerform(BatchOperations.java:159)”、“org.neo4j.server.rest.batch.NonStreamingBatchOperations.performBatchJobs(NonStreamingBatchOperations. java:48)”、“org.neo4j.server.rest.web.BatchOperationService.batchProcess(BatchOperationService.java:117)”、“org.neo4j.server.rest.web.BatchOperationService.performBatchOperations(BatchOperationService.java:72) ", "java.lang.reflect.Method.invoke(Method.java:606)", "org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112)" ],\n "全名" : "java.lang.NumberFormatException"\n }\n}', u'fullname': u'org.neo4j.server.rest.domain.BatchOperationFailedException', u'exception': u'批处理操作失败异常'}

4

1 回答 1

0

在您的代码示例中,n实际上将包含一个节点列表,而不是单个节点(请参阅create方法上的警告)。所以,而不是...

n = graph_db.create({"name": "Smith"})

……你可能想要……

n, = graph_db.create({"name": "Smith"})
于 2013-08-23T11:12:55.943 回答