title: JPA 3 level inheritance
body: <p>First of all I've been all the morning seeking for a solution for my problem. I've found similar problems but no one fixed my problem :(</p>
  
  <p>I have a 3 level inheritance on my Java classes model:</p>
  
  <pre><code>A &lt;-- B &lt;-- C
  </code></pre>
  
  <p>Mapping this into a Relational Data Base I've made
  <code>A (1) -- (0..1) B (1) -- (0..1) C</code>, so my annotated Java classes are something like:</p>
  
  <pre><code>@Entity
  @Inheritance(strategy=InheritanceType.JOINED)
  @DiscriminatorColumn(name="type", discriminatorType=DiscriminatorType.INTEGER)
  @XmlRootElement
  public class A implements Serializable {
      @Id
      @GeneratedValue(strategy=GenerationType.IDENTITY)
      private Long idA;
      private Integer type;
      ...
  }
  
  @Entity
  @DiscriminatorValue("2")
  @PrimaryKeyJoinColumn(name="idB", referencedColumnName="idA")
  @XmlRootElement
  public class B extends class A implements Serializable{
      private Long idB;
      private Integer type;
      @OneToOne(cascade={CascadeType.REMOVE}, fetch=FetchType.LAZY)
      @JoinColumn(name = "idB") 
      private A a;
      ...
  }
  
  @Entity
  @DiscriminatorValue("8")
  @PrimaryKeyJoinColumn(name="idC", referencedColumnName="idB")
  @XmlRootElement
  public class C extends class B implements Serializable{
      private Long idC;
      @OneToOne(cascade={CascadeType.REMOVE}, fetch=FetchType.LAZY)
      @JoinColumn(name = "idC") 
      private B b;
      ...
  } 
  </code></pre>
  
  <p>I don't know why, invoking a Query <code>SELECT c FROM C c</code> retrieves me <code>0</code> result when I have info on that table. If I do the query <code>SELECT b FROM B b</code> it works fine. It seems to be something wrong with the hierarchy annotations I've used.</p>
  
  <p>Any idea? Thank you in advance :)</p>