[英]Neo4j - Unable to create Relationship entities
我试图在Neo4j中插入两个节点之间的关系。 我使用的是Neo4J(2.1.8社区)和spring-data-neo4j(3.3.0.RELEASE)。
我正在尝试创建Employee-Manager关系。 此关系实体是报告。 (两个班级如下)
但是,当我试图保存关系船
Employee manager = new Employee("Dev_manager", "Management");
Employee developer = new Employee("Developer", "Development");
developer.setReportsTo(manager);
developer.relatedTo(manager, "REPORTS_TO")
employeeRepository.save(developer);
我被例外了
线程“main”中的异常org.springframework.dao.DataRetrievalFailureException:RELATIONSHIP [0]没有propertyKey =“ type ”的属性。 嵌套异常是org.neo4j.graphdb.NotFoundException:RELATIONSHIP [0]没有propertyKey =“ type ”的属性。
任何人都可以帮助我,这个代码中的错误是什么。
在我更改Employee中的关系类型后,相同的代码工作
@RelatedToVia(type = "REPORT_TO", elementClass = Report.class, direction = Direction.INCOMING)
注意:我在本教程中使用此参考。
Employee.java类
@NodeEntity
public class Employee {
@GraphId
private Long id;
private String name;
private String department;
@Fetch
@RelatedTo(type = "REPORTS_TO")
private Employee reportsTo; //Employee reports to some employee (i.e. Manager).
@Fetch
@RelatedTo(type = "REPORTS_TO", direction = Direction.INCOMING)
Set<Employee> directReport; //All the employees who reports to this particular this employee.
@Fetch
@RelatedToVia(type = "REPORTS_TO", elementClass = Report.class, direction = Direction.INCOMING)
Set<Report> relations = new HashSet<Report>(); // All the incoming relationship entities.
//*** Constructor, Getter-setters and other methods...
}
Report.java类
@RelationshipEntity(type = "REPORTS_TO")
public class Report {
@GraphId
private Long id;
private String title;
@Fetch
@StartNode
private Employee child;
@Fetch
@EndNode
private Employee parent;
//*** Constructor, Getter-setters and other methods...
}
**更新:**我使用这个类结构创建了2个关系。 我得到了以下结果。
看起来它在节点之间创建了2个关系。 1是使用reportsTo(即REPORTS_TO)的空关系和使用关系的另一种关系(即REPORT_TO)。 任何人都可以请更新为什么会发生这种情况?
relations
和directReport
之间有什么不同?
我认为SDN只是与所有重复的关系列表混淆了?
ESP。 如果它们曾被宣布为没有类型的轻关系,而曾被称为关系实体。
我认为对于这种情况,它更清晰,更容易使用
template.createRelationshipBetween(employee, manager, "REPORTS_TO");
或者只是创建,填充和保存关系实体Report
。
否则,您必须确保所有方面的所有集合彼此一致。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.