Issue with Tree using AbstractBackEndHierarchicalDataProvider!

I am trying to implement a lazy loading tree.

Followed the example here:

Implemented the three methods and set the provider to Tree.

The problem is that the methods ‘getChildCount’ and ‘fetchChildrenFromBackEnd’ are gettinng called 4 times!
This causes major issues when using heavy queries.

The weird thing is that these methods get called 4 times even with zero child nodes.


 public int getChildCount(HierarchicalQuery<ItemBean, Void> query) {
 return 0;
 protected Stream fetchChildrenFromBackEnd(HierarchicalQuery<ItemBean, Void> query) {
 return new LinkedList().stream();
  public boolean hasChildren(ItemBean item) {
  return false;

Is this a known issue or expected behavior? What can I do to ensure the calls are made just once.

Using Vaadin 8.8.2.

Is this a known issue

This is not reported as issue in or The code is quite same in both frameworks, so if this happens in Vaadin 8, I expect it to happen with Flow as well

or expected behavior?

By brief checking it looks like so. The TreeGrid code does not take into account that e.g. hasChildren already will produce back end call, see e.g.

This is because internal logic of DataProvider is abstracted away from TreeGrid.

What can I do to ensure the calls are made just once.

The most straightforward way to help the situation is to use some mechanism of caching. Easiest approach is perhaps to use cache with your backend, like ehcache.

So, if there are 1000 nodes then there will be 8000 database calls made! Not to mention the poor user interface experience that will result from constant rendering of the tree structure.

I can try caching but am afraid it could grow tremendously as number of sessions grow and does not appear to be a solid solution.

Isn’t this a bug or some tree implementation issue? Why would these methods be called 4 times each? Does not make sense. I will open an issue in the link you provided so that the Vaadin team is aware of it.