铸造节点neo4j的问题

时间:2015-07-22 05:03:06

标签: java neo4j cypher

我的代码在下面,根据文档,它应该给我节点值,但是它让我异常



Exception in thread "main" java.lang.ClassCastException: scala.collection.convert.Wrappers$SeqWrapper cannot be cast to org.neo4j.graphdb.Node
	at com.neo4j.performance.FetchData.main(FetchData.java:32)



 我使用的是Neo4j 2.2.2。

import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Result;
import org.neo4j.graphdb.Transaction;
import java.util.Iterator; 
import org.neo4j.helpers.collection.IteratorUtil;




import com.neo4j.enitites.Global;

public class FetchData {
     public static void main(String[] args) throws Exception  
        {

         String nodeResult = null;
         try ( Transaction ignored = Global.db.beginTx();
                  Result result = Global.db.execute( "MATCH path=()-[:route_1*]-() RETURN nodes(path) AS result" ) )
            {
                // START SNIPPET: items
                Iterator<Node> n_column = result.columnAs( "result" );
                for ( Node node : IteratorUtil.asIterable( n_column ) )
                {
                    nodeResult = node + ": " + node.getProperty( "StationCode" );
                }
                // END SNIPPET: items


            }

         System.out.println(nodeResult);
        }
}

我已经搜索了错误,但只有2或3个帖子也没有用。有没有人遇到过这个问题或者这个代码有问题。 感谢

1 个答案:

答案 0 :(得分:0)

在事务try-with-resources块中使用此代码段:

        for (Object cell : IteratorUtil.asIterable(result.columnAs("result"))) {
            Iterable<Node> nodes = (Iterable<Node>) cell;
            for (Node n : nodes) {
                System.out.println(n);
            }
        }
相关问题