简体   繁体   中英

How Neo4j ogm return result set for a Cypher query?

I'm new with Neo4j OGM so I create a simple example to understand how neo4j ogm work. I use Movie graph.

My Movie class :

@NodeEntity(label="Movie")
public class Movie extends Entity {

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

@Property(name="released")
private int released;

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

public Movie(){

}

public Movie(String titre, int year, String tagline){
    this.title = titre;
    this.released = year;
    this.tagline = tagline;
}

@Relationship(type = "ACTED_IN", direction = Relationship.INCOMING)
private Set<Person> actors = new HashSet<Person>();

public String getTitle(){
    return title;
}

public int getReleased(){
    return released;
}

public void setTitle(String ptitle){
    this.title = ptitle;
}

public void setReleased(int pReleased){
    this.released = pReleased;
}

public String getTagline(){
    return this.tagline;
}

public void setTagline(String pTagline){
    this.tagline = pTagline;
}


public Set<Person> getActors(){
    return this.actors;
}


public void setActors(Set<Person> actors){
    this.actors = actors;
}

@Override
public String toString(){
    return "Movie {" + "id=" + getLId() +
                 ",title=" + title + ",released="+ released + ",tagline="+ tagline +"}";

}

And, I try get data form the movie graph with a simple query:

String query = "MATCH (p:Person {name:'Keanu Reeves'})-[r:ACTED_IN]->(m:Movie) RETURN p";

    Iterable<Person> lperson = session.query(Person.class, query, Collections.emptyMap());

    for (Person person : lperson) {
        System.out.println(person.getName());
    }

In my opinion, the result set of this query will be : "Keanu Reeves" but Neo4j Ogm give me 7 times "Keanu Reeves" :

在此处输入图片说明

So because Keanu plays in 7 movies, and then Neo4j ogm return 7 times "Keanu Reeves". I want to knows if my perspective is correct or not ?

Can I return a sub-graph with Neo4j-ogm using Cypher ? ex : Keanu and all his movies, in java : person.getMovies(); If it's possible then what I need to do ?

Thanks you in advance and sorry for my bad English.

请确保您使用的是OGM的最新版本(1.1.4),并且您的图形仅包含一个表示Keanu Reeves的节点(即您没有多次加载电影数据库)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM