How do I practice recursion problems

Java Recursion problem in list created via csv file

Hello,

I would like to use a recursive method to read a certain value from a list, which results from an input value. Specifically, I read in a csv file using smooks and use it to create a list of entries from the CategoryHierarchy class. This in turn has 2 values, cid and cidParent(both long), which come directly from the csv file. As the name suggests, there is a tree-like hierarchy stored there. And I want to know the root node for each content (it can of course happen, the pid == root).
I try the whole thing as follows, but only the first parent node is returned to me instead of walking the tree all the way to the top:

Code:


In the specific case, 1100402 is displayed as the root. But 110 would be correct (this value is only available as cidParent and never as cid).
Structure of the CategoryHierarchy class:

Code:


Structure of the csv:
cid | cidParent
11032|110
11004|110
1100402|11004
110040202|1100402
110040204|1100402
110040206|1100402
...

I don't really know what the problem is. But I can at least narrow it down to how it works if I create a list of CategoryHierarchy instances with manually entered values. Reading in the csv works correctly, which I can see on the HTML report.

Thanks and best regards