【发布时间】:2017-04-30 22:00:39
【问题描述】:
以下详细信息将描述我的问题。
框架:Spring boot
数据库:Neo4j 嵌入式模式
存储库:GraphRepository
以下是我的组织 POJO
@NodeEntity
public class Organization extends UserBaseEntity {
@NotNull(message = "error.Organization.name.notnull")
private String name;
private String email;
@Relationship(type = HAS_SUB_ORGANIZATION)
private List<Organization> children = new ArrayList<>();
// getter and setters
}
目前尝试过:
使用具有特定深度的 findOne。
例如:
graphRepo.findOne(organizationId,3);
这将返回完整的组织网络。
我需要为组织生成层次结构数据。
有没有办法进行递归查询以生成组织层次结构。
我只需要 id、name、children(子组织)
示例格式
[
{
id: 1,
name: 'Organization 1',
children: [
{ id: 2, name: 'Organization 1 ' },
{ id: 3, name: 'Organization 2' }
]
},
{
id: 4,
name: 'Organization 2',
children: [
{
id: 5,
name: 'Organization 2 unit'
}
]
}
]
【问题讨论】:
-
您是否尝试过使用带有
@Query注释的自定义存储库查询?
标签: java neo4j spring-data cypher spring-data-neo4j