title: Primefaces tree from database
body: <p>I have the following entity class :</p>
  
  <pre><code>@Entity
  @Table(name = "THE_TREE", catalog = "", schema = "dbo")
  public class TheTree implements Serializable {
  private static final long serialVersionUID = 1L;
  @Id
  @Column(name = "ID", nullable = false)
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Long id;
  
  @Column(name = "NODE_NAME")
  private String name;
  
  @Column(name = "LEVEL")
  private int level;
  
  @OneToMany    
  @JoinColumn(name="PARENTID")    
  public List&lt;TheTree &gt; children = new LinkedList&lt;TheTree &gt;();
  </code></pre>
  
  <p>I would like to represent this into primefaces tree, but I cant get it right. The example given in <a href="http://www.primefaces.org/showcase-labs/ui/treeAjax.jsf" rel="nofollow noreferrer">primefaces</a> website has static nodes with predefined depth, where I need nodes with unknown depth and to be filled from database. I have seen various posts here but nothing is clear to me. In this <a href="https://stackoverflow.com/questions/6660458/how-to-create-a-dynamic-tree">post</a> it seems the author has asked the same question but the answer is not relative to the question somehow. Any solution would be appreciated.</p>