title: JPA oneToMany self mapping
body: <p>i have a jpa entity mapped as : </p>
  
  <pre><code>@Entity
  @Table(name = "CATEGORIES")
  public class Category {
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "ID_CATEGORY")
      private int idCategory;
  
      @Column(name = "POSITION")
      private int position;
  
      @Column(name = "SEO_VALUE")
      private String seoValue;
  
      @Column(name = "VALUE")
      private String value;
  
      @Column(name = "DESCRIPTION")
      private String description;        
  
      @Column(name = "SMART_CODE")
      private String smartCode;
  </code></pre>
  
  <p>I need to join Category with himself using the SMART_CODE field .
  I tried mapping as : </p>
  
  <pre><code>    @OneToMany(mappedBy="smartCategory")
      private List&lt;Category&gt; smartList = new ArrayList&lt;Category&gt;();
  
      @ManyToOne
      @JoinColumn(name="SMART_CODE", referencedColumnName="SMART_CODE",insertable=false,         updatable=false)
      private Category smartCategory;
  </code></pre>
  
  <p>but it doesn't works .</p>
  
  <p>I have a table Categories that have a field SMART_CODE . 
  The SMART_CODE is used to join records inside the table like : </p>
  
  <pre><code>    idCategory .. ... ... .. SMART_CODE
  
      1          .. ... ... .. 2000034
      2          .. ... ... .. 2000034 
      .................................
      100        .. ... ... .. 2000034
  </code></pre>
  
  <p>I want to map my Category Entity to get a list of categories with the same SMART_CODE (smartList) .</p>
  
  <p>Can anyone help me? </p>
  
  <p>Thanks </p>
  
  <p>Carlo</p>