title: How to declare a base repository for a MappedSuperclass base type with spring data?
body: <p>We're having a hierarchy of entity classes where all inherit from a BaseEntity @MappedSuperclass. Is there a way to have a spring-data "base repository" that allows you to query for any BaseEntity without having to know it's type and use a specific repository?</p>
  
  <pre class="lang-java prettyprint-override"><code>@MappedSuperclass
  public class BaseEntity {
      @Id
      private Long id;
      private String owner;
      // setter/getter etc...
  }
  
  @Entity
  public class FooEntity extends BaseEntity {
      private String foo;
  }
  
  @Entity
  public class BarEntity extends BaseEntity {
      private String bar;
  }
  
  /**
   * How to declare this base repository....
   */
  public interface BaseRepository extends JpaRepository&lt;BaseEntity, ActionPK&gt; {
      List&lt;BaseEntity&gt; findByOwner(String owner);
  }
  
  
  @Component
  public class MyService {
      @Autowired
      private BaseRepository baseRepository;
  
      public void doSomething() {
          // ... so that is can be used like this:
          List&lt;BaseEntity&gt; entities = baseRepository.findByOwner("john");
          doSomethingWith(entities);
      }
  }
  </code></pre>