title: Hibernate Inheritance - Getting superclass instance and casting into subclass
body: <p>Consider this scenario.</p>
  
  <p>There are plots, some are residential plots and some are commercial plots.</p>
  
  <p>There are also owners. But an owner can buy only a plot and it can be residential or commercial.</p>
  
  <p>So, here is my code.</p>
  
  <pre><code>@Entity
  @Table(name = "PLOT")
  @Inheritance(strategy = InheritanceType.JOINED)
  public abstract class Plot {
    private int id;
    private String number;
    private List&lt;Owner&gt; owners = new ArrayList&lt;&gt;();
  
    // getters and setters...
  }
  
  
  @Entity
  @Table(name = "RESIDENTIAL_PLOT")
  @PrimaryKeyJoinColumn(name = "PLOT_ID")
  public class ResidentialPlot extends Plot {
    // Some fields
  }
  
  
  @Entity
  @Table(name = "COMMERCIAL_PLOT")
  @PrimaryKeyJoinColumn(name = "PLOT_ID")
  public class CommercialPlot extends Plot {
    // Some fields
  }
  
  
  @Entity
  @Table(name = "OWNER")
  public class Owner {
    private int id;
    private String name;
    private Plot plot;
  
    // getters and setters
  }
  </code></pre>
  
  <p>All works well, but when I call <code>owner.getPlot()</code>
  I was expecting <code>ResidentialPlot</code> or <code>CommercialPlot</code> instance
  So, I can apply appropriate operation by using <code>instanceof</code> operator.
  But it does not satisfy both conditions!</p>
  
  <p>What am I doing wrong?</p>