title: Hibernate @ManyToOne Referenced Class using @NaturalId instead of @Id
body: <p>I have some Hibernate/JPA annotations (still don't know the difference to be honest) that are allowing me to create an association class.  This class is combining two items that are related into one object.  I originally was using <code>@JoinTable</code> but realized I needed a lot more meta data with the associations, so had to convert the code over into another object type.</p>
  
  <p>For now I am using <code>@Id</code> to mark the <code>ID</code> column for my objects, and using <code>@NaturalId (mutable = false)</code> for a <code>String uuid</code>.</p>
  
  <p>My association class is using <code>@ManyToOne</code> and creates the table just fine, but when I look into it the table is using the <code>@Id</code> field as the mapping column.  I would prefer to have this association class use the <code>@NaturalId uuid</code> for ease of transferring relationship/associations across to other systems.</p>
  
  <p>How can I get the relationship to use the correct identifier?</p>
  
  <p>For reference, my DB's and Java code look like this:</p>
  
  <pre><code>AssociationsTable
  ----------------------------------------------
  | ID | META DATA | ID ASSOC. 1 | ID ASSOC. 2 |
  ----------------------------------------------
  | 1  |  stuff    |    1        |     2       |
  ----------------------------------------------
  
  Objects
  ------------------------------
  | ID | META DATA | UUID      | 
  ------------------------------
  | 1  |  stuff    |  FOO-123  |
  ------------------------------
  | 2  |  stuff    |  BAR-456  |
  ------------------------------
  
  Association Class{
    ObjA main;
    ObjA sub;
  
    @ManyToOne
    getMain()
  
    @ManyToOne
    getSub()
  }
  
  ObjA Class{
    Long id;
    @Id
    @GeneratedValue(generator="increment")
    @GenericGenerator(name="increment", strategy = "increment")
    @XmlElement
    @Column(name = "ID", unique = true, nullable = false)
    getId()
  
    String uuid;    
    @NaturalId (mutable = false)
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "uuid2")
    @Column(name = "uuid", unique = true)
    getUUID()
  }
  </code></pre>