title: Bi-directional one-to-many with inheritance not working (jpa with hibernate 3.5.4)
body: <p>I am trying to map a bi-directional one-to-many relationship. I am having some trouble as the "many" side references an abstract superclass. While searching the internet for possible causes I discovered that this is a known problem but I wasn't able to find a solution for my case.</p>
  
  <p>I have checked the workarounds on <a href="http://chriswongdevblog.blogspot.be/2009/10/polymorphic-one-to-many-relationships.html" rel="nofollow">this</a> blog and the "Single table, without mappedBy" looks like a solution but I really need the bi-directional association.</p>
  
  <p>These are the classes I am trying to map:</p>
  
  <p>Owning Side</p>
  
  <pre><code>@Entity(name = "CC_Incl_Site")
  public class IncludedSite {
      @OneToMany(fetch=FetchType.LAZY, mappedBy = "includedSite")
      private Set&lt;CtaContractBase&gt; ctas = new HashSet&lt;CtaContractBase&gt;();
  
      @OneToMany(fetch=FetchType.LAZY, mappedBy = "includedSite")
      private Set&lt;WoContractBase&gt; wos = new HashSet&lt;WoContractBase&gt;();  
  }
  </code></pre>
  
  <p>Other Side:</p>
  
  <pre><code>@Entity
  public abstract class SCContract extends Contract {
  
      @ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
      @JoinColumn(name = "incl_site_id")
      private IncludedSite includedSite;
  }
  </code></pre>
  
  <p>Contract (the superclass of SCContract):</p>
  
  <pre><code>@Entity(name = "CC_CONTRACT")
  @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
  @DiscriminatorColumn(name = "contractType", discriminatorType = DiscriminatorType.STRING)
  @ForceDiscriminator
  public abstract class Contract {
  
  ...
  
  }
  </code></pre>
  
  <p>When trying to run the application I get this exception:</p>
  
  <p>mappedBy reference an unknown target entity property: 
  CtaContractBase.includedSite in IncludedSite.ctas</p>
  
  <p>Another solution appears to be replacing the @Entity annotation in SCContract with @MappedSuperClass but this results in another exception (Use of @OneToMany or @ManyToMany targeting an unmapped class: StudyContract.contracts[SCContract]) because in another class (StudyContract) I have </p>
  
  <pre><code>@OneToMany(fetch = FetchType.LAZY, mappedBy = "studyContract", targetEntity = SCContract.class)
  @BatchSize(size = 10)
  private Set&lt;SCContract&gt; contracts;
  </code></pre>
  
  <p>and as the blog explains having a collection of the superclass is not possible anymore using this approach.</p>
  
  <p>Are there any other workarounds or am I missing something?</p>