我在下面附加了两个通过关系连接的简单节点。为简洁起见,我省略了构造函数、getter 和 setter。
@NodeEntity
public class Person {
@Id
@GeneratedValue
private Long id;
private String name;
@Relationship(type = "ACTED_IN")
private List<Movie> movies = new ArrayList<>();
}
@NodeEntity
public class Movie {
@Id
@GeneratedValue
private Long id;
private String title;
@JsonIgnoreProperties("movie")
@Relationship(type = "ACTED_IN", direction = Relationship.INCOMING)
private List<Role> roles;
}
@RelationshipEntity(type = "ACTED_IN")
public class Role {
@Id
@GeneratedValue
private Long id;
@StartNode
private Person person;
@EndNode
private Movie movie;
}
我的问题如下。如果如果使用存储库接口加载一个人,我会看到电影列表总是空的。即使该人与电影有关系(“ACTED_IN”),也会发生这种情况。
如果我同时加载电影,我会看到角色列表已正确填充。这是预期的行为吗? 我觉得有点奇怪?有人可以给出更好的解释。