title: Creating an Association With an Entity Super Class Using JPA
body: <p>I have a simple class hierarchy of entities like so:</p>
  
  <pre>
  Permissable  (super class)
  \
   PermissableResource (sub class)
  </pre>
  
  <p>They are persisted in a table like so:</p>
  
  <pre>
  Permissable
  -------------
  id          PK
  resource    FK Resource(resourceId) 
  </pre>
  
  <p>I have another entity called <code>Resource</code> that I want to create an association with. It is persisted in a table like so:</p>
  
  <pre>
  Resource
  -------------
  resourceId    PK
  </pre>
  
  <p>In my <code>PermissableResource</code> class, I create the association like so:</p>
  
  <pre><code>@JoinColumn(name="resource", referencedColumnName="resourceId")
  @ManyToOne
  Resource resource;
  </code></pre>
  
  <p>The issue comes with the Resource class. I would like to have a reference to the super class <code>Permissable</code> and not the subclass <code>PermissableResource</code>. I try to create the association like so:</p>
  
  <pre><code>@OneToOne(mappedBy="resource", cascade= CascadeType.ALL, targetEntity=PermissableResource.class)
  private Permissable permissiable;
  </code></pre>
  
  <p>But this causes the following error on deployment:</p>
  
  <pre><code>Exception Description: The attribute [permissiable] in entity class [class com.dv.oa.model.entity.resource.Resource] has a mappedBy value of [resource] which does not exist in its owning entity class [class com.dv.oa.model.entity.permission.permissable.Permissable]. If the owning entity class is a @MappedSuperclass, this is invalid, and your attribute should reference the correct subclass.. Please see server.log for more details.
  </code></pre>
  
  <p>Its looking in <code>Permissable</code> for the association and not in <code>PermissableResource</code></p>
  
  <p>I thought that since I use the <code>targetEntity</code> attribute of <code>@OneToOne</code> and point it at <code>PermissableResource.class</code> this would work. How can I keep a super class reference in my entity, but map it to the subclass?</p>