title: Id mapping for entities extending a base entity with a generic Id
body: <p><strong>Situation</strong>: JPA 2.1, entities extending a <strong>base entity with a generic id</strong>.</p>
  
  <p>Interface for an <code>Entity</code> with a generic id:</p>
  
  <pre><code>public interface Entity&lt;ID extends Serializable&gt; extends Serializable {
      public ID getId();
      public void setId(ID id);
  }
  </code></pre>
  
  <p>Base implementation (abstract), defines some additional common attributes:</p>
  
  <pre><code>public abstract class BaseEntity&lt;ID extends Serializable&gt; implements Entity&lt;ID&gt; {
  
      private LocalDateTime creationTimestamp;
      private LocalDateTime lastModificationTimestamp;
      private Long version;
      private ID id;
  
      // getters and setters
  }
  </code></pre>
  
  <p>Some concrete entities: <code>Person</code>, whose id is an <code>UUID</code> which gets assigned before persisting:</p>
  
  <pre><code>public class Person extends BaseEntity&lt;UUID&gt; {
  
      public Person() {
          setId(UUID.randomUUID());
      }
      // attributes, getters and setters
  }
  </code></pre>
  
  <p>and <code>Address</code>, whose ids are <code>Long</code> and are generated by a sequence:</p>
  
  <pre><code>public class Address extends BaseEntity&lt;Long&gt; {
      // attributes, getters and setters
  }
  </code></pre>
  
  <p>O/R-mapping:</p>
  
  <p>
      </p>
  
  <pre><code>&lt;mapped-superclass class="idx.evaluation.jpa.hibernate.framework.BaseEntity"&gt;
      &lt;attributes&gt;
          &lt;basic name="creationTimestamp"&gt;
              &lt;column name="created" updatable="false" /&gt;
          &lt;/basic&gt;
          &lt;basic name="lastModificationTimestamp"&gt;
              &lt;column name="last_modified" /&gt;
          &lt;/basic&gt;
          &lt;version name="version"&gt;
              &lt;column name="version" /&gt;
          &lt;/version&gt;
      &lt;/attributes&gt;
  &lt;/mapped-superclass&gt;
  
  &lt;entity class="idx.evaluation.jpa.hibernate.model.Person"&gt;
      &lt;table name="person" /&gt;
      &lt;attributes&gt;
          &lt;id name="id"&gt;
              &lt;column name="id" nullable="false" unique="true" /&gt;
          &lt;/id&gt;
          &lt;!-- more attributes --&gt;
      &lt;/attributes&gt;
  &lt;/entity&gt;
  
  &lt;entity class="idx.evaluation.jpa.hibernate.model.Address"&gt;
      &lt;table name="address" /&gt;
      &lt;attributes&gt;
          &lt;id name="id"&gt;
              &lt;column name="id" nullable="false" unique="true" /&gt;
              &lt;generated-value strategy="SEQUENCE" generator="id_sequence" /&gt;
          &lt;/id&gt;
          &lt;!-- more attributes --&gt;
      &lt;/attributes&gt;
  &lt;/entity&gt;
  </code></pre>
  
  <p>My IDE (Eclipse 4.5) issues a warning on the id attributes of <code>Person</code> and <code>Address</code>:<br/> <em>"Attribute "id" is inherited; referring to inherited attributes in the orm.xml may not be supported by all persistence 
   providers"</em> </p>
  
  <p>When running tests, I get the following exception:</p>
  
  <pre><code>javax.persistence.PersistenceException: Unable to build entity manager factory
  ...
  Caused by: org.hibernate.AnnotationException:
  No identifier specified for entity: idx.evaluation.jpa.hibernate.model.Person
  </code></pre>
  
  <p><strong>Question</strong>: how can I realize such a mapping, where the base class defines a generic Id attribute, but the Id is differently mapped/generated per subclass? 
  I made another attempt by using <code>attribute-override</code> on the id, which worked for <code>Person</code> but not for <code>Address</code> (as I can't specify a <code>generated-value</code> for the override, but want to use a sequence there).</p>
  
  <p>Any help/hints are appreciated, thanks.</p>