2013-08-22 70 views
0

我使用py2neo將數據轉儲到Neo4j數據庫中。Py2neo - 在writebatch中創建關係

有了這個

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和1.9.2的Neo4j

感謝

  • 錯誤消息:

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'message': u'{\n "message" : "For input string: \"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" : "For input string: \"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.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 "fullname" : "java.lang.NumberFormatException"\n }\n}', u'fullname': u'org.neo4j.server.rest.domain.BatchOperationFailedException', u'exception': u'BatchOperationFailedException'}

回答

0

在你的代碼示例,n實際上將包含一個節點列表,而不是單個節點(請參閱create方法中的警告)。所以,與其...

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

...你可能想...

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