是否有可能请建议我如何去做.. 做一个相同的实体关系..
例如。实体(类人)关联到实体(类人)。
代码:
@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 is null)
return connectedPersons;
}
}
代码:
@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;
}
我正在尝试与同一个类建立关系..即连接到人的人..当我调用 Junit 测试时:
Person one = new Person ("One");
Person two = new Person ("Two");
personService.save(one); //Works also when I use template.save(one)
personService.save(two);
Iterable<Person> persons = personService.findAll();
for (Person person: persons) {
System.out.println("Person Name : "+person.getPersonName());
}
one.connectsTo(two, "Sample Connection");
template.save(one);
当我尝试做时我得到空指针one.connectsTo(two, "Prop");
请你告诉我哪里出错了?
提前致谢。