简体   繁体   English

Neo4j - 无法创建关系实体

[英]Neo4j - Unable to create Relationship entities

I am trying to insert the relationships between two nodes in Neo4j. 我试图在Neo4j中插入两个节点之间的关系。 I am using the Neo4J(2.1.8 Community) & spring-data-neo4j(3.3.0.RELEASE). 我使用的是Neo4J(2.1.8社区)和spring-data-neo4j(3.3.0.RELEASE)。

I am using trying to create the Employee-Manager relationship. 我正在尝试创建Employee-Manager关系。 This relationship entity is Report. 此关系实体是报告。 (Both class are given below) (两个班级如下)

But when I am trying to save the relation ship 但是,当我试图保存关系船

Employee manager = new Employee("Dev_manager", "Management");
Employee developer = new Employee("Developer", "Development");
developer.setReportsTo(manager);
developer.relatedTo(manager, "REPORTS_TO")
employeeRepository.save(developer);

I am getting exception as 我被例外了

Exception in thread "main" org.springframework.dao.DataRetrievalFailureException: RELATIONSHIP[0] has no property with propertyKey=" type ".; 线程“main”中的异常org.springframework.dao.DataRetrievalFailureException:RELATIONSHIP [0]没有propertyKey =“ type ”的属性。 nested exception is org.neo4j.graphdb.NotFoundException: RELATIONSHIP[0] has no property with propertyKey=" type ". 嵌套异常是org.neo4j.graphdb.NotFoundException:RELATIONSHIP [0]没有propertyKey =“ type ”的属性。

Can any one please help me that what is exactly wrong in this code. 任何人都可以帮助我,这个代码中的错误是什么。

The same code works after I change the type of relations in Employee as 在我更改Employee中的关系类型后,相同的代码工作

@RelatedToVia(type = "REPORT_TO", elementClass = Report.class, direction = Direction.INCOMING)

Note: I am using this reference for this tutorial. 注意:我在本教程中使用参考。

Employee.java class 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 class 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...
}

**Update: ** I have created 2 relations using this class structure. **更新:**我使用这个类结构创建了2个关系。 And I got the below result. 我得到了以下结果。 在此输入图像描述

It looks like it creates 2 relations between the node. 看起来它在节点之间创建了2个关系。 1 is empty relation using reportsTo(ie REPORTS_TO) and another relation using the relations(ie REPORT_TO). 1是使用reportsTo(即REPORTS_TO)的空关系和使用关系的另一种关系(即REPORT_TO)。 Can anyone please update why this is happening? 任何人都可以请更新为什么会发生这种情况?

What's the different between: relations and directReport ? relationsdirectReport之间有什么不同?

I think SDN is just confused with all the duplicate listing of relationships? 我认为SDN只是与所有重复的关系列表混淆了?

Esp. ESP。 if they are once declared as light relationships without type and once as relationship-entities. 如果它们曾被宣布为没有类型的轻关系,而曾被称为关系实体。

I think for this case it is much clearer and easier to use 我认为对于这种情况,它更清晰,更容易使用

template.createRelationshipBetween(employee, manager, "REPORTS_TO");

Or just create, populate and save the relationship-entity Report . 或者只是创建,填充和保存关系实体Report

Otherwise you have to make sure that all collections on all sides are consistent with each other. 否则,您必须确保所有方面的所有集合彼此一致。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM