Monta
Monta

Reputation: 1180

How to return nodes and relationships with Neo4j spring data repository

Is there any way to return somehow a list of {relationship,node} couples using spring data and cypher?

Ex: Suppose I have the graph "User visited Cities":

(User 1) -[r1] -> (New York)
(User 1) -[r2] -> (Paris)
(User 1) -[r3] -> (Madrid)

What I want to find is (or similar structure): Given the {user = "User 1"}, return :

[r1], (New York)
[r2], (Paris)
[r3], (Madrid)

PS :relationships has date property, that's why I want to return it with each city node.

Upvotes: 1

Views: 983

Answers (1)

Monta
Monta

Reputation: 1180

I had to create a class and Annotate it like this :

@QueryResult
public class NodeAndRelationship {

    @ResultColumn("node")
    private Node node;
    @ResultColumn("rel")
    private Relationship rel;
//getters and setters
}

Upvotes: 3

Related Questions