Reputation: 13
I have a Person node and a call relationship.I want to find a specific person and those who called him.My code are as below
@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();
}
Use test method I can retrieve the properties of the person node but the relationship property contact is null. How can I fix this?
Upvotes: 0
Views: 60
Reputation: 673
I had the same problem with null relationships. I think the only way to fetch relationships is by using cypher query language. Correct the mistake meistermeir point out. Try adding this method to your repository class.
@Query("MATCH (p:Person) WHERE ID(p)=18565124452 MATCH (p)-[call:Call*]->(p2) return p, call, p2")
Person getPersonById(long personId);
Also, I think you need to change :
@Property(name = "id")
to
@Id
@GeneratedValue
private Long id;
in order to generate unique id's every time you create new Person nodes.
Upvotes: 0
Reputation: 8262
Looks like an older Spring Data Neo4j version. But this shouldn't be a problem here. In your person class you are defining
@Relationship(type="Call",direction=Relationship.OUTGOING)
private List<Person> contact;
where it should be
@Relationship(type="Call",direction=Relationship.OUTGOING)
private List<Call> contact;
Upvotes: 1