title: Hibernate JPA inherited id mapping
body: <p>First of all, I'm very new to JPA and Hibernate Annotations.</p>
  
  <p>I have many systems and solutions developed in my current framework which is based on hibernate 3.5 and hbm.xml on Data Access Layer. Now I've decided to move to hibernate 4.1 and Annotation and get rid of hbm.xml files.</p>
  
  <p>But here comes my problem.</p>
  
  <p>I've a base class for ALL of my entities named GenericEntity which contains "id" and some other fields(like "version" and ...). This GenericEntity <b>IS NOT</b> mapped to any physical table directly and each entity is responsible to map these fields into physical table/column.</p>
  
  <p>Now in Annotation, I couldn't find any way to omit id and version fields/annotations in entities</p>
  
  <p>here are what I have:</p>
  
  <pre><code>public abstract class GenericEntity implements Serializable {
  
      public static final short UNSAVED_VALUE = -1;
  
      private long id = UNSAVED_VALUE;
      private int version;
  
      ... getters and setters
  }
  
  public class User extends GenericEntity {
  
      private String username;
      private String password;
      ... getters and setters
  }
  </code></pre>
  
  <p>and the hbm.xml is </p>
  
  <pre><code>&lt;class name="my.User" table="TBL_USER" optimistic-lock="version"&gt;
      &lt;id name="id" column="USR_ID" unsaved-value="-1"&gt;
          &lt;generator class="identity"/&gt;
      &lt;/id&gt;
  
      &lt;version name="version" column="USR_VERSION"/&gt;
      &lt;property name="username" column="USR_USERNAME" type="string" /&gt;
      &lt;property name="password" column="USR_PASSWORD" type="string" /&gt;
  &lt;/class&gt;
  </code></pre>
  
  <p>there is no mapping for GenericEntity and there is no inheritance mapping for User about GenericEntity.</p>
  
  <p>How Can I do that with annotation?!!</p>
  
  <p>a solution is to define getId and setId as abstract methods, but I can not add id and version to tens of thousand of my entities.</p>
  
  <p>also, I can not use hibernate inheritance for GenericEntity. because, I can not change my current tables easily and at the other hand it cost lots of penalty for performance. </p>
  
  <p>also, I want to minimize change on other parts of my framework. GenericEntity is widely used in DAL.</p>
  
  <p>Thanks</p>
  
  <p>Meysam Te.  </p>