Skip to main content

3.2 Limit Depth

Query Dynamic Entities

TreeNodeTable table = TreeNodeTable.$;

List<TreeNode> rootNodes = sqlClient
.createQuery(table)
.where(table.parentId().isNull())
.select(
table.fetch(
TreeNodeFetcher.$
.allScalarFields()
.recursiveChildNodes(
cfg -> cfg.depth(2)
)
)
)
.execute();

The currently queried aggregate roots are defined as the 0th layer. On this basis, query two layers of child objects downwards to obtain the following data:

[
{
"id":1,
"name":"Home",
"childNodes":[
{
"id":2,
"name":"Food",
"childNodes":[
{"id":3,"name":"Drinks"},
{"id":6,"name":"Bread"}
]
},
{
"id":9,
"name":"Clothing",
"childNodes":[
{"id":10,"name":"Woman"},
{"id":18,"name":"Man"}
]
}
]
}
]
info

The deepest 4 objects do not have the childNodes property as [], but do not have the childNodes property at all.

This means whether these 4 objects have subordinate objects is unknown, because the recursion process was prematurely terminated due to manual intervention.

Query Static DTO

Restricting recursion depth for static DTOs will be provided in later versions, please wait for later versions.