title: Bidirectional One-To-Many-relation between two (table-per-class)-inheritance trees
body: <p><strong>ABSTRACT</strong></p>
  
  <p>Say, I have two simple @Entity inheritance trees (one abstract base class with two concrete implementation classes in each tree) of InheritanceType.TABLE_PER_CLASS; and I need a bidirectional @OneToMany relation connecting the base classes using a @JoinColumn.</p>
  
  <p>This should produce <em>four</em> tables, one per concrete class, right? EclipseLink produces a fifth table for one of the abstract base classes which does not make sense to me. Consider this example (this is not a real-world example; it is just about JPA):</p>
  
  <p><strong>EXAMPLE</strong></p>
  
  <p>Collection is the abstract root of the first inheritance tree and implementor of the @OneToMany relation:</p>
  
  <pre><code>@Entity
  @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
  public abstract class Collection {
      @Id @GeneratedValue
      public long id;
      @OneToMany(mappedBy="collection")
      public List&lt;Media&gt; items = new ArrayList&lt;Media&gt;();
  }
  </code></pre>
  
  <p>PhysicalCollection and VirtualCollection are concrete implementations of Collection:</p>
  
  <pre><code>@Entity
  public class PhysicalCollection extends Collection {}
  
  @Entity
  public class VirtualCollection extends Collection {}
  </code></pre>
  
  <p>Media is the abstract root of the second inheritance tree and implementor of the @ManyToOne relation:</p>
  
  <pre><code>@Entity
  @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
  public abstract class Media {
      @Id
      @GeneratedValue
      public long id;
      @ManyToOne
      @JoinColumn(nullable = false)
      public Collection collection;
  }
  </code></pre>
  
  <p>CdMedia and TapeMedia are concrete implementations of Media:</p>
  
  <pre><code>@Entity
  public class CdMedia extends Media {}
  
  @Entity
  public class TapeMedia extends Media {}
  </code></pre>
  
  <p><strong>RESULT</strong></p>
  
  <p>As I said, EclipseLink will produce <em>five</em> tables from this (don't mind the SEQUENCE table):</p>
  
  <pre><code>mysql&gt; SHOW TABLES;
  +--------------------+
  | Tables_in_test     |
  +--------------------+
  | CDMEDIA            |
  | MEDIA              |
  | PHYSICALCOLLECTION |
  | SEQUENCE           |
  | TAPEMEDIA          |
  | VIRTUALCOLLECTION  |
  +--------------------+
  6 rows in set (0.00 sec)
  </code></pre>
  
  <p>And the unexpected table MEDIA will have a useless definition (the foreign key target changes semantics when renaming PhysicalCollection):</p>
  
  <pre><code>CREATE TABLE `MEDIA` (
      `COLLECTION_ID` bigint(20) NOT NULL,
      KEY `FK_MEDIA_COLLECTION_ID` (`COLLECTION_ID`),
      CONSTRAINT `FK_MEDIA_COLLECTION_ID` FOREIGN KEY (`COLLECTION_ID`) REFERENCES PHYSICALCOLLECTION` (`ID`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
  </code></pre>
  
  <p><strong>QUESTIONS</strong></p>
  
  <ol>
  <li>Are my expectiations correct? (Create 4 tables, not 5)</li>
  <li>Can someone confirm that this is a bug in EclipseLink?</li>
  <li>If not a bug, can you point out where I make a mistake?</li>
  </ol>