title: Does Spring Data Jpa supports repository inheritance and how to do?
body: <p>I have a simple entity inheritance tree composed of the following:</p>
  
  <pre class="lang-java prettyprint-override"><code>abstract class Item (id, ...)
  class Chart extends Item (...)
  class Table extends Item (...)
  </code></pre>
  
  <p>Each class has its own repository: <code>ItemRepository</code>, <code>ChartRepository</code> and <code>TableRepository</code>. All three repositories are <strong>exposed</strong>.</p>
  
  <p>Because of domain rules, I need to implement custom logic on delete, as explained here: <a href="http://docs.spring.io/spring-data/jpa/docs/1.10.3.RELEASE/reference/html/#repositories.custom-implementations" rel="nofollow noreferrer">http://docs.spring.io/spring-data/jpa/docs/1.10.3.RELEASE/reference/html/#repositories.custom-implementations</a></p>
  
  <p>This custom delete logic concerns all entities in the inheritance tree (the abstract one and the two concretes).</p>
  
  <p>Is there a way to implement custom logic on the <code>ItemRepository</code> and make the repositories of the children entities extend <code>ItemRepository</code>? </p>
  
  <p>This would avoid duplicate of the same logic for each entity of the inheritance tree. Without that this makes a lot of boilerplate classes :</p>
  
  <p><code>EntityRepository</code> + <code>EntityRepositoryCustom</code> + <code>EntityRepositoryImpl</code> x <code>3 entities</code> = <code>9 classes</code> just to implement 1 ligne of code to be executed on delete...</p>
  
  <p><strong>EDIT</strong> </p>
  
  <p>The answer of user <code>user7398104</code> got me on the way to implement things as explained <a href="https://stackoverflow.com/a/27549198/5276344">here</a> and <a href="http://blog.netgloo.com/2014/12/18/handling-entities-inheritance-with-spring-data-jpa/" rel="nofollow noreferrer">there</a>, but theses resources do not explain how to implement a custom repository on the <code>@NoRepositoryBean</code> base repository. I tried the following without luck:</p>
  
  <pre><code>@NoRepositoryBean
  public interface ItemBaseRepository&lt;T extends Item&gt; extends 
      CrudRepository&lt;T, Integer&gt;,
      ItemBaseRepositoryCustom&lt;T&gt;
  
  @RepositoryRestResource
  public interface ItemRepository extends ItemBaseRepository&lt;Item&gt; {}
  
  @RepositoryRestResource
  public interface ChartRepository extends ItemBaseRepository&lt;Item&gt; {}
  
  @RepositoryRestResource
  public interface TableRepository extends ItemBaseRepository&lt;Item&gt; {}
  
  public interface ItemBaseRepositoryCustom&lt;T extends Item&gt; {
      public void delete (T i);
  }
  
  public class ItemBaseRepositoryImpl&lt;T extends Item&gt;
      implements ItemBaseRepositoryCustom&lt;T&gt; {
  
      public void delete (T i) {
          // Custom logic
      }
  
  }
  </code></pre>
  
  <p><strong>EDIT EDIT</strong></p>
  
  <p>I tried to set <code>@NoRepositoryBean</code> to ItemBaseRepositoryCustom as suggested on comments but it doesnt work either.</p>