Expanding and selecting items in a lazy TreeGrid

Using Vaadin 14.1.17 I’ve got a lazy loaded TreeGrid which displays all of my hierarchical data but is collapsed in the beginning.
Besides that I have a Grid which displays a list of search-results (which is based on that hierarchical data but ignores the hierarchy-level).

Problem 1: SOLVED
When I select an item of the Grid and the TreeGrid is fully expanded (manually) I want it to be selected in the TreeGrid too.
The ValueChangeListener of the Grid is triggered with the correct item but the select()-call seems to be ignored by the TreeGrid, the displayed Objects of TreeGrid and Grid are the same.

Answer: Category.java was missing an equals() and hashCode() method

Problem 2:
When I select an item of the Grid and the TreeGrid is collapsed I want to expand it until the item is visible.
What’s the best-practice here?

My sample code-base:

final HierarchicalDataProvider<Category, Void> dataProvider = new AbstractBackEndHierarchicalDataProvider<>() {
    public int getChildCount(final HierarchicalQuery<Category, Void> hierarchicalQuery) {
        final String parentUuid = hierarchicalQuery.getParentOptional()
        return categoryRepository.countByParentUuid(parentUuid);

    public boolean hasChildren(final Category category) {
        final String parentUuid = Optional.ofNullable(category)
        return categoryRepository.existsByParentUuid(parentUuid);

    protected Stream<Category> fetchChildrenFromBackEnd(final HierarchicalQuery<Category, Void> hierarchicalQuery) {
        final String parentUuid = hierarchicalQuery.getParentOptional()
        return categoryRepository.findByParentUuid(parentUuid).stream();

final TreeGrid<Category> lazyTree = new TreeGrid<>();

final Grid<Category> searchGrid = new Grid<>();

// display search results independent of their hierarchy-level

searchGrid.asSingleSelect().addValueChangeListener(e -> {

    // problem 1: (isn't selecting the item even if it's expanded and visible)
	//            SOLVED by adding equals() and hashCode()

    // problem 2: what's the best way to expand the tree until the item is visible?
    //            (i could backtrace the parents until the root and then work my way down by expanding them?)

add(lazyTree, searchGrid);

After thinking about possible solutions, this is the best I found for problem 2:

searchResults.asSingleSelect().addValueChangeListener(e -> {
	backtrackParents(treeGrid::expand, e.getValue());
private void backtrackParents(Consumer<Collection<Category>> fn, final Category value) {
	final List<Category> path = new ArrayList<>();
	Category currentCategory = value;
	while (currentCategory != null && currentCategory.getParentUuid() != null) {
		currentCategory = categoryRepository.getByUuid(currentCategory.getParentUuid());