title: Hibernate one to one mapping on composite foreign key and primary key in single table
body: <p>I have a Catagory table, with composite primary key and foreign key. My table structure is like </p>
  
  <pre><code>CREATE TABLE CATAGORY (
    CATAGORY_ID int(11) NOT NULL,
    CATAGORY_NAME varchar(50) DEFAULT NULL,
    VERSION int(11) NOT NULL,
    PARENT_ID  int(11) DEFAULT NULL,
    PRIMARY KEY (CATAGORY_ID,VERSION)
  );
  
  ALTER TABLE CATAGORY ADD CONSTRAINT FOREIGN KEY (PARENT_ID, VERSION) REFERENCES CATAGORY (CATAGORY_ID, VERSION); 
  </code></pre>
  
  <p>and I want a ORM mapping with Catagory class like this</p>
  
  <pre><code>public class Catagory {
      @EmbeddedId
      private CatagoryPk pk ;
      @Column(name="CATAGORY_NAME")
      private String  catagoryName;
  
      private Catagory parentId;
  
      private List&lt;Catagory&gt; childs ;                 
  
  }
  @Embeddable
  public class CatagoryPk {
      @Column(name="VERSION")
      private Integer version;
      @Column(name="CATEGORY_ID")
      private Integer catagoryId;
  }
  </code></pre>
  
  <p>Now how to annotate </p>
  
  <pre><code>private Catagory parentId;  
  private List&lt;Catagory&gt; childs ;  
  </code></pre>