title: JPA ManyToOne mapping with Inheritance
body: <p>I have a couple of entities, that have common attributes, hence extracted the common params like the below snippet.</p>
  
  <pre><code>@MappedSuperclass()
  public class BaseCustomerDemographicDetails {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      protected long id;
  
      @ManyToOne
      @JoinColumn(name = "GROUP")
      protected Group group;
  
  }
  </code></pre>
  
  <p>The Entity snippets are as below.</p>
  
  <pre><code>@Entity
  @Table(name = "INDIVIDUAL_CUSTOMER")
  @Access(AccessType.FIELD)
  public class IndividualCustomer extends BaseCustomerDemographicDetails {
  
      @NotNull
      @Embedded
      private PersonalInformation personalInformation;
  
      @Column(precision = 16, scale = 2)
      private BigDecimal annualIncome;
  
      private Boolean vip;
  
      private Boolean isStaff;
  
  ...
  }
  </code></pre>
  
  <hr>
  
  <pre><code>    @Entity
      @Access(AccessType.FIELD)
      @Table(name = "GROUP")
      public class Group {
  
          protected Group(){}
  
          @Id
          @NotNull
          @Column(name = "GROUPID")
          private String groupId;
  
          @NotNull
          @Column(name="GROUPNAME")
          private String groupName;
  
          @OneToMany(fetch = FetchType.LAZY, mappedBy = "group")
          private List&lt;BaseCustomerDemographicDetails&gt; customerDemographicDetails;
  
      }
  </code></pre>
  
  <p>The OneToMany mapping of the same results in Hibernate exception during statrtup as below. </p>
  
  <pre><code>Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
   at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1249)
   at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.access$600(EntityManagerFactoryBuilderImpl.java:120)
   at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:860)
   at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
   at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425)
   at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849)
   at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)
   at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343)
   at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:319)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
   ... 16 common frames omitted
  Caused by: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: xx.xxx.xxxxxxx.xxxxxxxxx.domain.model.Group.customerDemographicDetails[xx.xxx.xxxxx.xxxxxxx.domain.model.BaseCustomerDemographicDetails]
   at org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1135)
   at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:794)
   at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:729)
   at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:70)
   at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1697)
   at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1426)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846)
   at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857)
   ... 24 common frames omitted
  </code></pre>
  
  <p>Isn't that how <a href="http://docs.oracle.com/javaee/5/api/javax/persistence/MappedSuperclass.html" rel="nofollow noreferrer"><code>@MappedSuperclass</code></a> is supposed to be used?</p>