Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Grails 在同一测试中创建节点时,无法使用graphDatabaseService找到该节点_Grails_Neo4j_Gorm - Fatal编程技术网

Grails 在同一测试中创建节点时,无法使用graphDatabaseService找到该节点

Grails 在同一测试中创建节点时,无法使用graphDatabaseService找到该节点,grails,neo4j,gorm,Grails,Neo4j,Gorm,作为 我现在有一个测试,如下所示: 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())

作为

我现在有一个测试,如下所示:

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
据我从上述线程中了解,这应该是获取节点的可能方法之一。还是我错了?

试试下面的代码片段(没有测试我自己,只是一个大脑转储):


我对grails接口不太熟悉,但是像创建新节点这样的写操作经常需要事务,而您没有事务。可能包含您正在编写的节点的事务在您尝试查找该节点之前没有提交?因此,这似乎对我起到了作用:
String label=find.getClass().simpleName def graphNodes=graphDatabaseService.FindNodesByBeland属性(DynamicLabel.label(label),“\uu id\uuuu”,found.id)断言graphNodes[0]instanceof org.neo4j.graphdb.Node断言graphNodes[0]。hasRelationship()==false
但它不应该与findById()相同吗?
def nodeInstance = ....
nodeInstance.save(flush:true)

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