Neo4jRepository 中的 findAll 方法 returns null for nested attributes

The findAll method in Neo4jRepository returns null for nested attributes

我的程序结构是:

School.java

@NodeEntity
@NoArgsConstructor
@Getter
@Setter
public class School extends Entity {
    private String name;
    @Relationship(type = "UNDER")
    private Board board;
    private String address;
    private String phone;

    @Override
    public String toString() {
        return "School{" +
                "name='" + name + '\'' +
                ", board=" + board +
                ", address='" + address + '\'' +
                ", phone='" + phone + '\'' +
                '}';
    }
}

Board.java

@NodeEntity
@NoArgsConstructor
@Getter
@Setter
public class Board extends Entity {
    private String name;
    @Relationship(type = "HAS")
    private List<Grade> grades;

    @Override
    public String toString() {
        return "Board{" +
                "name='" + name + '\'' +
                ", grades=" + grades +
                '}';
    }
}

SchoolRepository.java

@Repository
public interface SchoolRepository extends Neo4jRepository<School, Long> {
}

这是一个 spring-boot 项目,我有相关的控制器和服务。

问题是 boardgradesschoolRepository.findAll() returns 为空。

但是数据库中显示的是完整的数据。

我大摇大摆的输出:

[
  {
    "id": 5,
    "name": "Bishops",
    "board": {
      "id": 14,
      "name": "CBSE",
      "grades": null
    },
    "address": "Nagpur",
    "phone": "1234567891"
  },
  {
    "id": 15111,
    "name": "Conrads",
    "board": {
      "id": 15132,
      "name": "ICSE",
      "grades": null
    },
    "address": "Agra",
    "phone": "789456123"
  }
]

我做错了什么?

这是因为 findAll 的默认深度是 1。所以 School 和它的 Board 被加载,而不是 [=12= 的 Grades ] 因为成绩在学校的深度 2。

如果将深度参数 2 传递给 findAll,将加载成绩。