How do I query for paths in spring data neo4j 4?

旧巷老猫 提交于 2019-11-27 07:12:30

问题


In an earlier version of spring data neo4j (3.3.1), I was able to query for paths in my database and return them as Iterable<EntityPath<S,E>> like this:

public interface ArgumentNodeRepository extends GraphRepository<ArgumentNode> {
    @Query("START t=node({0}), r=node({1}) MATCH p=t<-[:SUPPORTED_BY|INTERPRETS*0..]-r RETURN p")
    Iterable<EntityPath<ArgumentNode, ArgumentNode>> getPaths(long childId, long rootId);
}

I'm trying to migrate to 4.0.0 and the EntityPath class seems to have disappeared. I don't see any mention of EntityPath in the migration guide. What's my new return type?


回答1:


EntityPath isn't supported in SDN 4, but you can still query for paths. I have an example here which contains a Cypher query that returns a path- the return type is Iterable<Map<String, Object>>

This represents a collection of paths, each path containing a list of interleaved nodes and relationships in the path (nodes and relationships represented as a Map). An example of how I processed the path is https://github.com/luanne/flavorwocky/blob/sdn/src/main/java/com/flavorwocky/service/PairingServiceImpl.java#L57




回答2:


You could also Neo4jOperations for this. Just create a custom repository implementation (see http://docs.spring.io/spring-data/data-commons/docs/current/reference/html/#repositories.custom-implementations), and call the Neo4jOperations bean from there:

neo4jOperations.queryForObjects(ArgumentNode.class, "START t=node({0}), r=node({1}) MATCH p=t<-[:SUPPORTED_BY|INTERPRETS*0..]-r RETURN p")

This will return a list of ArgumentNodes



来源:https://stackoverflow.com/questions/32962032/how-do-i-query-for-paths-in-spring-data-neo4j-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!