java – Neo4j – 无法创建关系实体

我试图在Neo4j中插入两个节点之间的关系.我正在使用Neo4J(2.1.8社区)&弹簧数据的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);

我被例外了

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类

@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).任何人都可以请更新为什么会发生这种情况?

最佳答案 关系和directReport之间有什么不同?

我认为SDN只是与所有重复的关系列表混淆了?

ESP.如果它们曾被宣布为没有类型的轻关系,而曾被称为关系实体.

我认为对于这种情况,它更清晰,更容易使用

template.createRelationshipBetween(employee,manager,“REPORTS_TO”);

或者只是创建,填充和保存关系实体报告.

否则,您必须确保所有方面的所有集合彼此一致.

点赞