我是Neo4j OGM的新手,所以我创建了一个简单的例子来了解neo4j ogm是如何工作的。我用电影图。
我的电影课程:
@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 +"}";
}
而且,我尝试通过简单的查询从电影图中获取数据:
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());
}
在我看来,这个查询的结果集将是:“基努·里维斯” 但是Neo4j Ogm给了我7次“Keanu Reeves”:
因为基努在7部电影中播放,然后Neo4j ogm回归7次“基努·里维斯”。我想知道我的观点是否正确?
我可以使用Cypher返回带有Neo4j-ogm的子图吗? 例如:基努和他所有的电影,在java:person.getMovies(); 如果有可能那么我需要做什么?
提前谢谢你,抱歉我的英语不好。
答案 0 :(得分:0)
请确保您使用的是最新版本的OGM(1.1.4),并且您的图表只包含一个代表Keanu Reeves的节点(即您没有多次加载电影数据库)