java - NodeEntity 无法转换为 graphdb.Node

标签 java neo4j spring-data-neo4j neo4j-ogm

我有一个如下所示的 NodeEntity,我想对其使用 Pathfinder 算法。算法如下。不幸的是,我收到 neo4j.entity.Stop 无法转换为 org.neo4j.graphdb.Node 的错误

我该怎么办?我不知道如何让spring使用org.neo.graphalgo graphalgo库

private Path testGraphAlgoFactory(Stop s1, Stop s2){

 PathExpander expander = PathExpanders.allTypesAndDirections();

 PathFinder<Path> pathFinder =
                GraphAlgoFactory.shortestPath(expander , 6);

 Path path = pathFinder.findSinglePath((Node)s1, (Node)s2);
}

这是我的 NodeEntity 类,如下所示:

@NodeEntity
public class Stop {
    @GraphId
    private Long id;

    @Property(name="name")
    private String name;

    @Property(name="lon")
    private double longitude;

    @Property(name="lat")
    private double latitude;

    @Property(name="id")
    private String stopId;
}

最佳答案

如果您使用 OGM 将图中的节点转换为对象,这是一个有效的结果。 像 Stop 这样的类“只是”Java 类,并不知道它们有任何 Neo4j 起源。

除此之外(以及今天早些时候关于您的其他问题):图形算法旨在用作 Neo4j 中的插件,而不是作为应用程序代码的一部分。 Neo4j Graph Algorithms documentation

因此,在您的应用程序中使用 SessionFactory 并获取新的 Session 来运行调用 Neo4j 上算法的 cypher 语句可能会更容易。例如调用 algo.shortestPath(...)

另一个选择可能是您在 SpringData Neo4j 存储库中使用自定义查询,通过使用 @Query("CALL ...") 来执行查询语句。但您必须知道将从密码语句中返回什么。然后您可以将结果放入 @QueryResult 类中。 Sample from the docs (但不要创建内部类,而是在实体扫描路径中创建一个类)

关于java - NodeEntity 无法转换为 graphdb.Node,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48509276/

相关文章:

neo4j - 在返回之前过滤查询中关系属性的值

neo4j - 启动嵌入式 Neo4j HA Slave 时出现索引创建错误

示例代码的 Java/Android 包名

java - 使用 poi ,如何将单元格类型设置为数字

database - 将 JSON-LD 插入 Neo4j 的语义正确方法是什么?

date - 使用Spring Data neo4j比较日期

java - 无法将 spring-data-neo4j :2. 3.1.RELEASE 与 Gradle 一起使用

java - 创建一个 Student 将其传递给 SQL 对象并在线程 "AWT-EventQueue-0"lang.ArrayIndexOutOfBoundsException : 4 中获取异常

java - 从外部配置文件读取值返回空值

neo4j - 在 Neo4j 中将所有属性的所有值转换为小写