gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 03:20:49 25 4
gpt4 key购买 nike

我正在尝试在 Neo4j 中插入两个节点之间的关系。我正在使用 Neo4J(2.1.8 社区)和 spring-data-neo4j(3.3.0.RELEASE)。

我正在尝试创建员工-经理关系。这个关系实体是 Report。 (两个类都在下面给出)

但是当我试图挽救关系时

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 个关系。我得到了以下结果。 enter image description here

看起来它在节点之间创建了 2 个关系。 1 是使用 reportsTo(即 REPORTS_TO)的空关系,另一个使用关系(即 REPORT_TO)的关系。任何人都可以更新为什么会这样吗?

最佳答案

relationsdirectReport 之间有什么区别?

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

特别是如果它们曾经被声明为没有类型的轻型关系,并且曾经被声明为关系实体。

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

template.createRelationshipBetween(员工, 经理, "REPORTS_TO");

或者只是创建、填充和保存关系实体 Report

否则你必须确保所有方面的所有集合彼此一致。

关于java - Neo4j - 无法创建关系实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31025142/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com