title: JPA repository with single table inheritance (hibernate)
body: <p>I have created two entites (<code>RegularEmployee</code> and <code>ContactEntity</code>) that extends the <code>Employee</code> entity.</p>
  <pre><code>@Entity
  @Table(name=&quot;employees&quot;)
  @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
  @DiscriminatorColumn(name = &quot;type&quot;, discriminatorType = DiscriminatorType.STRING)
  @DiscriminatorValue(value=&quot;employee&quot;)
  public class Employee {
  
      @Id
      @GeneratedValue
      private Long id;
  
      private String name;
  
  ...
  </code></pre>
  <p>Im using <code>SINGLE_TABLE</code> inheritance for this implementations, and created a generic JpaRepository for manipulating data:</p>
  <pre><code>@Repository
  public interface EmployeeRepository&lt;T extends Employee&gt; extends JpaRepository&lt;T, Long&gt; {
  }
  </code></pre>
  <p>I've created also the Service class that autowire three instance of these generic repositories, and specific methods for each class.</p>
  <pre><code>@Service
  public class EmployeeService {
  
      @Autowired
      private EmployeeRepository&lt;Employee&gt; employeeRepo;
  
      @Autowired
      private EmployeeRepository&lt;RegularEmployee&gt; regularRepo;
  
      @Autowired
      private EmployeeRepository&lt;ContractEmployee&gt; contractRepo;
  
      public List&lt;Employee&gt; getAllEmployee() {
          return employeeRepo.findAll();
      }
  
      public List&lt;RegularEmployee&gt; getAllRegularEmployee(){
          return regularRepo.findAll();
      }
  
      public List&lt;ContractEmployee&gt; getAllContractEmployee() {
          return contractRepo.findAll();
      }
  ...
  
  </code></pre>
  <p>My problem is, that when I try to find all regular employees or contract employees, I always get all type of employees (employees, regular employees  and contract employees all together).</p>
  <p>I do not know why it behaves like this, even though the method's signature says it returns the appropriate type.</p>