2014-05-06 63 views
0

Trying out neo4j grails plugin, but it does not mach the docs找不到節點

延續我有一個測試,現在看起來是這樣的:

package com.iibs.graph 

import groovy.util.GroovyTestCase 
import com.iibs.graph.Node 

public class NodeTests extends GroovyTestCase { 

    def graphDatabaseService 

    void testCRUD() { 
     Node.deleteAll(Node.list()) 

     Node node = new Node(name: "Name") 

     node.save(flush: true, failOnError: true) 

     Node found = Node.findByName("Name") 

     assert found instanceof Node 
     assert found.getName() == "Name" 

     org.neo4j.graphdb.Node graphNode = graphDatabaseService.getNodeById(node.getId()) 

     assert graphNode.instanceOf(org.neo4j.graphdb.Node) == true 
    } 
} 

而且我如下得到一個錯誤:

| Running 1 integration test... 1 of 1 
| Failure: testCRUD(com.iibs.graph.NodeTests) 
| org.neo4j.graphdb.NotFoundException: Node 905482810884096 not found 
    at org.neo4j.kernel.InternalAbstractGraphDatabase.getNodeById(InternalAbstractGraphDatabase.java:1088) 
    at com.iibs.graph.NodeTests.testCRUD(NodeTests.groovy:22) 
    at junit.framework.TestCase.runTest(TestCase.java:176) 
    at junit.framework.TestCase.runBare(TestCase.java:141) 
    at junit.framework.TestResult$1.protect(TestResult.java:122) 
    at junit.framework.TestResult.runProtected(TestResult.java:142) 
    at junit.framework.TestResult.run(TestResult.java:125) 
    at junit.framework.TestCase.run(TestCase.java:129) 
    at junit.framework.TestSuite.runTest(TestSuite.java:255) 
    at junit.framework.TestSuite.run(TestSuite.java:250) 
| Completed 1 integration test, 1 failed in 0m 2s 

據我所知,從提到的線程,這應該是獲得節點的可能方式之一。或者我錯了?

+0

我不熟悉Grails的界面,但寫入操作如創建一個新的節點經常需要交易,你沒有一個。也許包含您正在編寫的節點的事務在您嘗試查找該節點之前未提交? – FrobberOfBits

回答

1

試試下面的代碼片段(沒有測試自己,只是一個題庫):

def nodeInstance = .... 
nodeInstance.save(flush:true) 

String label = nodeInstance.getClass().simpleName 
def neoNode = graphDatabaseService.findNodesByLabelAndProperty(DynamicLabel.label(label), "__id__", nodeInstance.id) 
+0

所以,這似乎是爲我工作: '字符串標籤= found.getClass()simpleName 高清graphNodes = graphDatabaseService.findNodesByLabelAndProperty(DynamicLabel.label(標籤), 「__id__」,found.id) 斷言graphNodes。 [0] instanceof org.neo4j.graphdb.Node assert graphNodes [0] .hasRelationship()== false' 但是不是它應該和findById()一樣嗎? –