我有一个Person节点和一个呼叫关系。我想找到一个特定的人以及给他打电话的人。我的代码如下
@NodeEntity
public class Person extends BaseEntity{
@Property(name = "id")
private String mobile;
private String name;
private int partition;
private int StronglyConnectedComponents;
private int ConnectedComponent;
private int LabelPropagation;
private double pagerank;
private int seed_label; //在线算法结果写回字段
@Relationship(type="Call",direction=Relationship.OUTGOING)
private List<Person> contact;
//setter and getter
}
@RelationshipEntity(type = "Call")
public class Call extends BaseEntity{
@StartNode
private Person caller;
@EndNode
private Person callee;
private String BS;
private String time;
//setter and getter
}
@Repository
public interface PersonRepository extends GraphRepository<Person>{
Person findById(String id, @Depth int depth);
}
public String test() {
Person person = community.personRepository.findById("18565124452",2);
return person.toString();
}
使用测试方法,我可以检索人员节点的属性,但是关系属性contact为空。我该如何解决?
答案 0 :(得分:1)
看起来像旧的Spring Data Neo4j版本。但这在这里应该不是问题。在个人课程中,您正在定义
@Relationship(type="Call",direction=Relationship.OUTGOING)
private List<Person> contact;
应该在哪里
@Relationship(type="Call",direction=Relationship.OUTGOING)
private List<Call> contact;
答案 1 :(得分:0)
我是neo4j的新手,我在空关系方面也遇到了同样的问题。我认为获取关系的唯一方法是使用密码查询语言。纠正meistermeir指出的错误。尝试在存储库类中添加此方法。
@Query("MATCH (p:Person) WHERE ID(p)=18565124452 MATCH (p)-[call:Call*]->(p2) return p, call, p2")
Person getPersonById(long personId);
我还认为您需要更改:
@Property(name = "id")
到
@Id
@GeneratedValue
private Long id;
为了在每次创建新的Person节点时生成唯一的ID。