title: How to mix inheritance strategies with JPA annotations and Hibernate?
body: <p>According to the <em>Hibernate Reference Documentation</em> it should be possible to mix different inheritance mapping strategies when using Hibernate's XML-Metadata:<br>
  <a href="http://docs.jboss.org/hibernate/stable/core/reference/en/html/inheritance.html#inheritance-mixing-tableperclass-tablepersubclass" rel="noreferrer">http://docs.jboss.org/hibernate/stable/core/reference/en/html/inheritance.html#inheritance-mixing-tableperclass-tablepersubclass</a></p>
  
  <p>However, the corresponding section of the <em>Hibernate Annotations Reference Guide</em> does not cover that:<br>
  <code>http://docs.jboss.org/hibernate/stable/annotations/reference/en/html/entity.html#d0e1168</code></p>
  
  <p>On the other hand, the JavaDocs suggest that mixing inheritance strategies should be possible. For instance in javax.persistence.DiscriminatorColumn it says:  </p>
  
  <blockquote>
    <p>The strategy and the discriminator column are only specified in the root of an entity class hierarchy <strong>or subhierarchy in which a different inheritance strategy</strong> is applied.</p>
  </blockquote>
  
  <hr>
  
  <p>The following is an example for the mapping I'm trying to achieve. I'd like to use <em>table-per-subclass</em> mapping near the root of the hierarchy, but change to <em>table-per-class-hierarchy</em> mapping near the leaves. Here's some example code:</p>
  
  <pre><code>@Entity
  @Inheritance( strategy = InheritanceType.JOINED )
  public abstract class A implements Serializable
  {
      @Id
      private String id;
  
      // other mapped properties...
  }
  
  @Entity
  @Inheritance( strategy = InheritanceType.SINGLE_TABLE )
  public class BB extends A
  {
      // other mapped properties and associations...
  }
  
  @Entity
  public class BB1 extends BB
  {
      // other stuff, not necessarily mapped...
  }
  
  @Entity
  public class BB2 extends BB
  {
      // other stuff, not necessarily mapped...
  }
  
  @Entity
  @Inheritance( strategy = InheritanceType.SINGLE_TABLE )
  public class CC extends A
  {
      // other mapped properties and associations...
  }
  
  @Entity
  public class CC1 extends CC
  {
      // other stuff, not necessarily mapped...
  }
  
  ...
  </code></pre>
  
  <p>What I expect from this mapping is having exactly 3 tables: <code>A</code>, <code>BB</code>, and <code>CC</code>. Both <code>BB</code> and <code>CC</code> should have a default discriminator column called <code>DTYPE</code>. They should also provide all columns necessary for all mapped properties and associations of their respective subclasses.</p>
  
  <p>Instead , the class hierarchy seems to use the <em>table-per-subclass</em> inheritance strategy throughout. I.e. I get an own table for each of the entities mentioned above. I'd like to avoid this, since the leaves of the class-hierarchy are extremely light-weight and it just seems overkill to have a separate table for each of them!</p>
  
  <hr>
  
  <p>Did I overlook something? Any advice is highly appreciated! I'll be glad to provide additional info...</p>