D.Ocean D.Ocean - 1 month ago 5
Java Question

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" :

enter image description here

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.

Answer

Please ensure you're using the latest version of the OGM (1.1.4), and that your graph contains just one node representing Keanu Reeves (i.e. you haven't loaded the movies database multiple times)

Comments