spring data - Neo4j Same Entity Relationship persistence issue -
is possible pls advice me how go about.. doing same entity relationship..
for ex. entity(class person) relatesto entity(class person).
code:
@nodeentity public class person { @graphid @generatedvalue private long id; @indexed(indextype = indextype.fulltext, indexname = "searchbypersonname") private string personname; @fetch @relatedto(type = "connects_to", direction = direction.both) private set<connectedpersons> connectedpersons; public connectedpersons connectsto(person endperson, string connectionproperty) { connectedpersons connectedpersons = new connectedpersons(this, endperson, connectionproperty); this.connectedpersons.add(connectedpersons); //null pointer here(connectedpersons null) return connectedpersons; } }
code:
@relationshipentity(type = "connected_to") public class connectedpersons{ @graphid private long id; @startnode private person startperson; @endnode private person endperson; private string connectionproperty; public connectedpersons() { } public connectedpersons(person startperson, person endperson, string connectionproperty) { this.startperson = startperson; this.endperson = endperson; this.connectionproperty = connectionproperty; }
i trying have relationship same class.. i.e. persons connected person.. when invoke junit test :
person 1 = new person ("one"); person 2 = new person ("two"); personservice.save(one); //works when use template.save(one) personservice.save(two); iterable<person> persons = personservice.findall(); (person person: persons) { system.out.println("person name : "+person.getpersonname()); } one.connectsto(two, "sample connection"); template.save(one);
i null pointer when try one.connectsto(two, "prop");
please tell going wrong?
thanks in advance.
one other thing besides missing initialization of set class connectedpersons @relationshipentity. in class person using @relatedto annotation if @nodeentity. should use @relatedtovia annotation in person class instead.
Comments
Post a Comment