title: Using the same column for multiple mappings in hibernate
body: <p>I have run my own tests and don't believe this is possible but was hoping to get some confirmation.</p>
  
  <p>I have two objects that are being persisted using hibernate, <code>Child</code> and <code>Parent</code>. A <code>Child</code> always has a reference to a single <code>Parent</code> and and <code>Parent</code> has a Set of <code>Child</code> Objects. On top of this a parent has a List of favorites which consists of Child objects.</p>
  
  <p>This is mapped using the following HBM definitions:</p>
  
  <pre><code>&lt;class name="Parent" table="parent"&gt;
      &lt;id name="id" column="id"&gt;
          &lt;generator class="increment"/&gt;
      &lt;/id&gt;
  
    &lt;set cascade="all,delete-orphan" inverse="true" name="children"&gt;
      &lt;cache usage="nonstrict-read-write"/&gt;
      &lt;key column="parent_id"/&gt;
      &lt;one-to-many class="Child"/&gt;
    &lt;/set&gt;
  
    &lt;list cascade="none" name="favorites"&gt;
      &lt;cache usage="nonstrict-read-write"/&gt;
      &lt;key&gt;
        &lt;column name="parent_id" not-null="false"/&gt;
      &lt;/key&gt;
      &lt;index&gt;
        &lt;column name="fav_index"/&gt;
      &lt;/index&gt;
      &lt;one-to-many class="Child"/&gt;
    &lt;/list&gt;
  &lt;/class&gt;
  
  &lt;class name="Child" table="child"&gt;
      &lt;id name="id" column="id"&gt;
          &lt;generator class="increment"/&gt;
      &lt;/id&gt;
    &lt;many-to-one column="parent_id" name="parent" not-null="false"/&gt;
  
  &lt;/class&gt;
  </code></pre>
  
  <p>The trouble I am having is with the column <code>parent_id</code> in the <code>child</code> table. It works fine when I persist Child objects that have references to a parent and when I persist Parent objects that have a list of favorites. However, when I try and remove a child from a parents list of favorites, the column <code>child.parent_id</code> gets set to null, even though I have not removed the Parent Object from the Child before it is persisted.</p>
  
  <p>From my tests, I don't think there is anyway around this other than using a different column name for the favorites key column in the Parent mapping. It just seems a bit of a shame to do that since these two columns will always have the same value.</p>
  
  <p>Does anyone if this is possible or will I have to use two columns?</p>
  
  <p>Thanks</p>