title: How to get all children of a parent and then their children using recursion
body: <p>Greetings:</p>
  
  <p>I have the metaphor of Parent Transactions in my JSP web application. I have transaction ID's stored in a database and the requirement is to display all of the children of the parent and then the subsequent children of the parent's children. In reality this list of parents and their children will never be more than 4 or 5 levels deep but I need to take into account that it can go more layers than that. </p>
  
  <p>I have tried doing this will recursion as follows:</p>
  
  <pre><code>private static void processChildrenTransactions(
      AllTremorTransactionsVO parentBean,
      ArrayList&lt;AllTremorTransactionsVO&gt; childCandidatesList )
  {
    ArrayList&lt;AllTremorTransactionsVO&gt; childList =
        new ArrayList&lt;AllTremorTransactionsVO&gt;();
  
    for (AllTremorTransactionsVO childTransactions : childCandidatesList)
    {
      if (childTransactions.getParentGuid() != null)
      {
        if (childTransactions.getParentGuid().equals(parentBean.getTransactionGuid()))
        {
          childList.add(childTransactions);
        }
      }
    }
  
    for (AllTremorTransactionsVO allTremorTransactionsVO : childList)
    {
      processChildrenTransactions(allTremorTransactionsVO, childList);    
    }
  
    return;
  }
  </code></pre>
  
  <p>This does not work, generates a stack overflow as the loop runs on. Any ideas on best how to do this? </p>