title: Hibernate, mapping inherited fields
body: <p>Lets say I have a following class hierarchy:</p>
  
  <pre><code>class Person {
      String name;
      int age;
  }
  class DatabasePerson extends Person {
      int databaseId;
  }
  </code></pre>
  
  <p>Now I would like to map the DatabasePerson, please notice that I don't would like to tell hibernate that there exist a Person class, hibernate should only know about the DatabasePerson  class while xml or annotation mapping. Is it possible to map the age and name fields with hibernate adopting the above mentioned condition ? In other words I would like to map the DatabasePerson class with hibernate and hibernate should not know about the Person class. In xml I would make it like this (Pseudo-code):</p>
  
  <pre><code>&lt;hibernate class="DatabasePerson"&gt;
       &lt;field name="id"/&gt;
       &lt;field name="name"/&gt;
       &lt;field name="age"/&gt;
  &lt;/hibernate&gt;
  </code></pre>
  
  <p>The reason for doing that is to keep the single responsibility principle. I don't would like to put the databaseId field into the Person class, because the person class shouldn't know that it is persisted. I don't would like to include any hibernate annotations into Person class because I have there pure entity logic and I don't want do import there any database related stuff like hibernate. All mappings I would like to do in the DatabasePerson class, this is the place where I would like to put the additional databaseId field, write hibernate annotations (or maybe xml, I don't know it right now, I would like to postpone this decision). I other words we want to keep the database related stuff and our application logic in separate classes. </p>
  
  <p>Edit:
  Can I use something like this?:
  </p>
  
  <pre><code>&lt;class name="Person" table="PERSON" discriminator-value="P"&gt;
  
  
      &lt;discriminator column="DISCRIMINATOR" type="string" /&gt;
  
      &lt;property name="name" /&gt;
      &lt;property name="age"  /&gt;
  
      &lt;subclass name="DatabasePerson" extends="Person" &gt;
          &lt;id name="databaseId" column="ID"&gt;
              &lt;generator class="native" /&gt;
          &lt;/id&gt;
  
      &lt;/subclass&gt;
  &lt;/class&gt;
  </code></pre>
  
  <p></p>
  
  <p>Notice that the database id is in the DatabasePerson scope in this xml.</p>
  
  <p>Edit:
  Is this xml mapping respective to the annotation 'mapped superclass' ? I think I preffer to use xml instead of annotations so my question is how to use @MappedSuperclass in xml:
  </p>
  
  <pre><code>&lt;class name="Person" table="PERSON" discriminator-value="P"&gt;
      &lt;id name="databaseId" column="PERSON_ID"&gt;
          &lt;generator class="native" /&gt;
      &lt;/id&gt;
  
      &lt;discriminator column="DISCRIMINATOR" type="string" /&gt;
  
      &lt;subclass name="DatabasePerson" extends="Person" discriminator-value="E"&gt;
              &lt;property name="name" column="name" /&gt;
              &lt;property name="age" type="int" column="age" /&gt;
      &lt;/subclass&gt;
  &lt;/class&gt;
  </code></pre>
  
  <p></p>