Spring Data Neo4j @Query 不返回子节点

标签 spring spring-boot graph neo4j spring-data-neo4j-4

我有四个通过独特关系相关的 pojo。
第一个 Employee 节点:

@NodeEntity
public class Employee {

    @GraphId
    private Long id;

    @Index(unique = true)
    private String employeeId;

    @Relationship(type = "HAS_POSITION", direction = Relationship.OUTGOING)
    private Position position;

    @Relationship(type = "HAS_SHIFT", direction = Relationship.OUTGOING)
    private List<ShiftDate> shiftDates = new ArrayList<>();

    @Relationship(type = "RESTRICTION_OF_EMPLOYEE", direction = Relationship.INCOMING)
    private List<Restriction> restrictions = new ArrayList<>();

    @Relationship(type = "PREFERENCE_OF_EMPLOYEE", direction = Relationship.INCOMING)
    private List<Preference> preferences = new ArrayList<>();

}

如您所见,它有四种关系。
我的 ShiftDate pojo 看起来像:

@NodeEntity

public class ShiftDate {

    @GraphId
    private Long id;

    private Date startDt;
    private Date endDt;

    private List<Date> dates = new ArrayList<>();

    @Relationship(type = "HAS_RESTRICTION", direction = Relationship.OUTGOING)
    private List<Restriction> restrictions = new ArrayList<>();

    @Relationship(type = "HAS_PREFERENCE", direction = Relationship.OUTGOING)
    private List<Preference> preferences = new ArrayList<>();
}

现在,限制偏好:

@NodeEntity
public class Restriction {

    @GraphId
    private Long id;

    private String from;
    private String to;
    private String notes;
}

@NodeEntity
public class Preference {

    @GraphId
    private Long id;

    private String from;
    private String to;
    private String notes;
}

问题是当我尝试从 Employee 节点获取 ShiftDate 详细信息时,它仅返回 ShiftDate 数据,而不返回首选项和限制数据。

我尝试过 Spring Data 的 List<ShiftDate> getShiftDatesByEmployeeId(String employeeId)方法无效。

已尝试

@Query("MATCH (employee:Employee{employeeId:{0}})-[has_shift:HAS_SHIFT]->(shiftDate:ShiftDate)
RETURN shiftDate");

还是不行。尝试过高级查询,例如

@Query("MATCH (employee:Employee)-[has_shift:HAS_SHIFT]->(shiftDate:ShiftDate)-[has_preference:HAS_PREFERENCE]-> (preference:Preference)
WITH employee,shiftDate,preference
MATCH (shiftDate)-[has_restriction:HAS_RESTRICTION]->(restriction:Restriction) WHERE employee.employeeId={0}
RETURN shiftDate,preference,restriction");

仍然无法工作。

谁能告诉我出了什么问题吗?

最佳答案

您还需要返回关系,这样 SDN 将填充您的子对象。

您的返回条款应如下所示:

RETURN shiftDate, has_preference, preference, has_restriction, restriction

关于Spring Data Neo4j @Query 不返回子节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48991744/

相关文章:

java - 过滤器在注册为 Spring bean 时调用两次

java - Camel : CamelFailureEndpoint not set when sending exchange to DeadLetterChannel

java - 如何使用 spring webflux 上传和读取文本文件?

r - 如何在 R 中创建带有辅助分组 x 轴的条形图?

android - AchartEngine 中的阈值?

javascript - 在 Highstock 的 x 轴上绘制数据

java - Spring MVC 表单验证不适用于嵌套的复杂类型

java - 在 Spring 中处理上下文

java - 如何在spring boot项目启动时创建目录

java - 将 Docker 和 docker compose 与 Spring Boot REST 应用程序结合使用