Modify child(s) of parent in TreeData

I’m trying to change the parent of all the children of a item that is to be removed. The code under will throw a null exception on the line esaveConfig.setParent(child, parent)

In the documentation the getChildren method should return a List of my object, but when i print the class I get a class java.util.Collections$UnmodifiableRandomAccessList. I guess the issue is that the objects is unmodifiable, but why is the intellisense showing that the method should return a List?

Any other approach to achive what I want would be appreciated!

Here is the code:

            EsaveObject parent = esaveConfig.getParent(esaveObjectBinder.getBean());
            System.out.println(childs.getClass());
            System.out.println(childs);
            for(EsaveObject child : childs) {
                System.out.println(child);
                esaveConfig.setParent(child, parent);
            }```

UnmodifiableRandomAccessList is a List. You aren’t allowed to change the items like that. Do the change on your original data in your Backend and after that refresh the data provider of the grid.

I don’t understand where I can change this any other way. What do you mean with the “original data in your Backend”? Please be more specific. The esaveConfig object is a TreeData object. The adding/removing/getting and setting of children and parent is done directly on this object providing it with a EsaveObject. The EsaveObject itself do not have any information on where it hierarchy is to be placed in the TreeData.

https://github.com/vaadin/flow/blob/c09aa1eed34cbb0ba62422ddbfe44547bdbceb7a/flow-data/src/main/java/com/vaadin/flow/data/provider/hierarchy/TreeData.java#L301 should be used instead of working on the children. Well somehow you have to get/query the tree data → in those code you should handle the correct addition and removal of items and afterwards refresh the tree data.

Yes this is what I want to do, but before i removeItem I want to take all the items children and give them a new parent instead of recursively remove them with the parent. It seemed like an easy solution to loop over the children and setParent but since the children in the list received is immutable I’m not able to do that. I guess this is a feature and not a bug? I am currently working on a workaround where the EsaveObject also stores its parent when put into the TreeGrid and also keeping a separat List of all EsaveObject and then manualy building up the TreeGrid again when removing an item. This seems cumbersome, and maybe not as intended. I have this nagging feeling of doing something wrong since I would think the purpose of the TreeData object where to not have to do this manually.

Removing single item causing cascade database delete needs to be fixed in backend. remove cascade.delete and add @preremove