0 Replies Latest reply on Jul 10, 2008 3:26 PM by Michael Bauer

    Circular references and Hibernate annotations

    Michael Bauer Newbie

      I am looking into creating a class in such a way that it can hold references to itself and a parent. In other words, I am looking to make a bi-directional tree of these classes.

      The class would like something like this:

      public class Sample {
       private String id;
       private Sample parent;
       private Set<Sample> children;
       public String getId(){ return id; }
       public void setId(String id) { this.id=id; }
       /** This is where I am confussed.... **/

      The proposed table for the above would be:
      varchar(256) id
      varchar(256) parentId

      I have made plenty of classes that reference one-to-many one way, and many-to-one the other, but this is the first time I have tried to make these connections within the same class. I guess I am just getting confused how to setup the JoinColumn name and the mappedBy in the annotations to work off a single table column within a single table.