title: Hibernate mappings with a discriminator
body: <p>I have a table with one field that can point to a foreign key in one of 3 other tables based on what the descriminator value is (Project, TimeKeep, or CostCenter.  Usually this is implemented with subclasses, and I am wondering if what I have below will work.  <strong>Note the subclass name is the same as the parent class and the noteObject property is mapped to an instance variable of type java.lang.Object</strong> so it should accept either a Project, TimeKeep or CostCenter object as long as we cast to the correct type.  Will hibernate allow this?  Thanks.</p>
  
  <pre><code>&lt;hibernate-mapping package="com.tlr.finance.mappings"&gt;
  
   &lt;class name="AdminNotes" table="admin_notes"&gt;
      &lt;id name="adminNoteId" column="admin_note_id" type="integer"&gt;
        &lt;generator class="identity" /&gt;
      &lt;/id&gt;
  
  &lt;discriminator column="note_type" type="string" /&gt;
  
  &lt;!-- make this property an enumerated type.  It is the discriminator --&gt;
  &lt;property name="adminNoteType" column="note_type" type="string" not-null="true" /&gt;
  &lt;property name="adminNote" column="note" type="string" not-null="true" /&gt;
  &lt;property name="adminNoteAdded" column="note_date" type="timestamp"
    not-null="true" /&gt; 
  
  &lt;subclass name="AdminNotes" discriminator-value="project" &gt;
    &lt;many-to-one name="noteObject" column="object_id" class="PsData" /&gt;&lt;!-- Project --&gt;
  &lt;/subclass&gt;
  
  &lt;subclass name="AdminNotes" discriminator-value="user" &gt;
    &lt;!-- rename timekeep to user --&gt;
    &lt;many-to-one name="noteObject" column="object_id" class="Timekeep" /&gt;&lt;!-- user --&gt;
  &lt;/subclass&gt;
  
  &lt;subclass name="AdminNotes" discriminator-value="costCenter" &gt;
    &lt;!-- rename timekeep to user --&gt;
    &lt;many-to-one name="noteObject" column="object_id" class="CostCenter" /&gt;&lt;!-- cost center --&gt;
  &lt;/subclass&gt;
  
    &lt;/class&gt;
  
  &lt;/hibernate-mapping&gt;
  </code></pre>