Neo4j - 无法创建关系实体
Neo4j - Unable to create Relationship entities
我正在尝试在 Neo4j 中插入两个节点之间的关系。我正在使用 Neo4J(2.1.8 社区) & spring-data-neo4j(3.3.0.RELEASE).
我正在尝试创建员工-经理关系。这个关系实体是 Report。 (下面都给出class)
但是当我试图保存关系时
Employee manager = new Employee("Dev_manager", "Management");
Employee developer = new Employee("Developer", "Development");
developer.setReportsTo(manager);
developer.relatedTo(manager, "REPORTS_TO")
employeeRepository.save(developer);
我收到异常
Exception in thread "main" org.springframework.dao.DataRetrievalFailureException: RELATIONSHIP[0] has no property with propertyKey="type".; nested exception is org.neo4j.graphdb.NotFoundException: RELATIONSHIP[0] has no property with propertyKey="type".
谁能帮我看看这段代码到底出了什么问题。
在我将 Employee 中的关系类型更改为
后,相同的代码仍然有效
@RelatedToVia(type = "REPORT_TO", elementClass = Report.class, direction = Direction.INCOMING)
注意:我正在使用本教程的 this 参考。
Employee.java class
@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 class
@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...
}
**更新:**
我使用这个 class 结构创建了 2 个关系。我得到了以下结果。
看起来它在节点之间创建了 2 个关系。 1 是使用 reportsTo(即 REPORTS_TO)的空关系,另一个使用关系(即 REPORT_TO)的关系。任何人都可以更新为什么会这样吗?
relations
和 directReport
之间有什么区别?
我认为 SDN 只是混淆了所有重复的关系列表?
Esp。如果它们曾经被声明为没有类型的轻型关系,并且曾经被声明为关系实体。
我认为对于这种情况,它更清晰易用
template.createRelationshipBetween(employee, manager, "REPORTS_TO");
或者只是创建、填充和保存关系实体 Report
。
否则你必须确保所有方面的所有集合彼此一致。
我正在尝试在 Neo4j 中插入两个节点之间的关系。我正在使用 Neo4J(2.1.8 社区) & spring-data-neo4j(3.3.0.RELEASE).
我正在尝试创建员工-经理关系。这个关系实体是 Report。 (下面都给出class)
但是当我试图保存关系时
Employee manager = new Employee("Dev_manager", "Management");
Employee developer = new Employee("Developer", "Development");
developer.setReportsTo(manager);
developer.relatedTo(manager, "REPORTS_TO")
employeeRepository.save(developer);
我收到异常
Exception in thread "main" org.springframework.dao.DataRetrievalFailureException: RELATIONSHIP[0] has no property with propertyKey="type".; nested exception is org.neo4j.graphdb.NotFoundException: RELATIONSHIP[0] has no property with propertyKey="type".
谁能帮我看看这段代码到底出了什么问题。
在我将 Employee 中的关系类型更改为
后,相同的代码仍然有效@RelatedToVia(type = "REPORT_TO", elementClass = Report.class, direction = Direction.INCOMING)
注意:我正在使用本教程的 this 参考。
Employee.java class
@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 class
@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...
}
**更新:**
我使用这个 class 结构创建了 2 个关系。我得到了以下结果。
看起来它在节点之间创建了 2 个关系。 1 是使用 reportsTo(即 REPORTS_TO)的空关系,另一个使用关系(即 REPORT_TO)的关系。任何人都可以更新为什么会这样吗?
relations
和 directReport
之间有什么区别?
我认为 SDN 只是混淆了所有重复的关系列表?
Esp。如果它们曾经被声明为没有类型的轻型关系,并且曾经被声明为关系实体。
我认为对于这种情况,它更清晰易用
template.createRelationshipBetween(employee, manager, "REPORTS_TO");
或者只是创建、填充和保存关系实体 Report
。
否则你必须确保所有方面的所有集合彼此一致。