【发布时间】:2013-08-27 02:52:22
【问题描述】:
是否有可能请建议我如何去做.. 做一个相同的实体关系..
例如。 实体(类人)关联到实体(类人)。
代码:
@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;
}
我正在尝试与同一类建立关系..即连接到 Person 的人..当我调用 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"); 时,我得到空指针
请问你能告诉我哪里错了吗?
提前致谢。
【问题讨论】:
标签: neo4j spring-data spring-data-neo4j