How is the order of adding items to a hierachical container for a tree impo

Hi everybody,
I have a huge Map with Objects (and their ids as keys) which are to be displayed in a hierachical tree.
Each object has a reference to the parent and its children.
Unfortunately the database is not returning the objects in a useful order.
I guess that a specific order is needed, when I want to add items to a HierachicalContainer, is it?
The tree isn’t looking like it should this way. I experienced the same behaviour with test data.
My guess is, that the root has to be the first and any “parents” before their children?
If so, do you have any ideas how I could solve this? I’m not sure if and how I could reorder them in the map.