私は以下の(プロジェクト、ユーザ、タスク)ドメインオブジェクトを持っています。 Spring Data Neo4j 4(SDN4)を使用して特定の関連オブジェクトを持つエンティティを取得するにはどうすればよいですか?たとえば、私は関連するタスクを持つプロジェクトをフェッチしたいが、ユーザーはいない。このサンプルは動作しません。 depth
をneo4jTemplate.load
の方法で定義することは、ユーザーオブジェクトを取得するため、私にとっては適切ではありません。Spring Data Neo4j経由で特定の関連オブジェクトを持つエンティティを取得するにはどうすればいいですか4
public Project findProjectWithTasks(Long projectId){
Project project = neo4jTemplate.load(Project.class, projectId, 0);
/*
project.id <- correct
project.name <- correct
project.tasks <- null, but in previous versions of Spring Data Neo4j I had empty entities with id
*/
Collection<Task> tasks = neo4jTemplate.loadAll(project.getTasks()); // <- returns null, because project.getTasks() is null
return project;
}
// ----------
@NodeEntity
class Project {
@GraphId
private Long id;
private String name;
@Relationship(direction = Relationship.OUTGOING, type = "PROJECT_TASK")
private Set<Task> tasks;
@Relationship(direction = Relationship.OUTGOING, type = "PROJECT_USER")
private Set<User> users;
}
@NodeEntity
class Task {
@GraphId
private Long id;
private String name;
@Relationship(direction = Relationship.INCOMING, type = "PROJECT_TASK")
private Project project;
@Relationship(direction = Relationship.OUTGOING, type = "TASK_USER_ASSIGNED")
private User assignedTo;
}
@NodeEntity
class User {
@GraphId
private Long id;
private String email;
@Relationship(direction = Relationship.INCOMING, type = "TASK_USER_ASSIGNED")
private Set<Task> tasks;
@Relationship(direction = Relationship.INCOMING, type = "PROJECT_USER")
private Set<Project> projects;
}