title: Cyclic relationships in Hibernate
body: <p>I want to map a tree in hibernate, but persisting it results in an exception because of the cyclic reference (the relationships are not bidirectional).</p>
  
  <pre><code>class Node {
      @ManyToOne
      Node parent;
  
      @OneToOne
      Node leftChild;
  
      @OneToOne
      Node rightChild;
  }
  </code></pre>
  
  <p>Node N references its left child L which in turn references N again as its parent. Also, node N references its right child R which in turn again references N again as parent. However, I cannot make the relationships bidirectional, because parent would be the inverse of both leftChild and rightChild. What is the best way to make this model persistable?</p>
  
  <p>Regards,
  Jochen</p>