title: Hibernate one to one relation on same object
body: <p>I have a transaction table which contains information about... transactions, some transactions are derived from a previous transaction, so that there can be a one to one relation between transactions.</p>
  
  <p>I'm trying to set up annotation in hibernate to create this data structure, but I wasn't able to figure out or find how to do it. </p>
  
  <pre><code>@Entity
  @Table(name="transaction")
  public class Transaction {
  private String transactionid;
  private Transaction derivedFrom;
  
     /**
       * @return the transactionid
       */
      @Id
      public String getTransactionid() {
          return transactionid;
      }
      /**
       * @param transactionid the transactionid to set
       */
      public void setTransactionid(String transactionid) {
          this.transactionid = transactionid;
      }
  
      @OneToOne(mappedBy = "transaction", cascade = CascadeType.ALL)
      public Transaction getDerivedFrom() {
          return derivedFrom;
      }
      public void setDerivedFrom(Transaction derivedFrom) {
          this.derivedFrom = derivedFrom;
      }
  
  }
  </code></pre>
  
  <p>Here is an example of code so you'll understand where I'm going with this... any idea on how to set up this relation?</p>