簡體   English   中英

Neo4j - 無法創建關系實體

[英]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)。 任何人都可以請更新為什么會發生這種情況?

relationsdirectReport之間有什么不同?

我認為SDN只是與所有重復的關系列表混淆了?

ESP。 如果它們曾被宣布為沒有類型的輕關系,而曾被稱為關系實體。

我認為對於這種情況,它更清晰,更容易使用

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

或者只是創建,填充和保存關系實體Report

否則,您必須確保所有方面的所有集合彼此一致。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM