【问题标题】:Issue of casting Node neo4j铸造节点 neo4j 的问题
【发布时间】:2015-07-22 05:03:06
【问题描述】:

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

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 个帖子也不起作用。有没有人遇到过这个问题或者这段代码有问题。 谢谢

【问题讨论】:

    标签: java neo4j cypher


    【解决方案1】:

    在事务 try-with-resources 块中使用这个 sn-p:

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

    【讨论】:

    • nodeResult 去哪儿了?这里我们只是打印一些东西。
    猜你喜欢
    • 2021-01-16
    • 1970-01-01
    • 2011-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-17
    相关资源
    最近更新 更多