title: Writing spring data repository for polymorphic entity - InheritanceType.SINGLE_TABLE
body: <p>Hello I have the following example:</p>
  
  <pre><code>@Entity
  @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
  @DiscriminatorColumn(name = "EVENT_TYPE")
  abstract class BaseEvent {
  }
  @Entity
  @DiscriminatorValue("ACCEPT_EVENT")
  class AcceptEvent {
  
  }
  
  @Entity
  @DiscriminatorValue("CANCEL_EVENT")
  class CancelEvent {
  
  }
  </code></pre>
  
  <p>I would like to write a repository for this Polymorphic entity. The thing is that I may have many EventTypes so I would prefer If I don't have to write One Repository class per Event Type. I was hoping that #{#entityName} can be applied in a generic repository like this:</p>
  
  <pre><code>interface EventRepositort&lt;T&gt; extends CRUDRepository&lt;T&gt; {
  
     @Query(select e from #{#entityName} e where e.completionDate is null)
     public T findIncompleteEvents();
  }
  </code></pre>
  
  <p>I was hoping that if I have a service and I inject the repository with specific generic type it will figure out what the #{#entityName} so I did the following:</p>
  
  <pre><code>@Service
  class EventService {
    @Autowire
    private EventRepository&lt;AcceptEvent&gt; acceptEventRepo;
  
    public runUnfinishedEvents() {
        List&lt;AcceptEvent&gt; unfinishedEvents = acceptEventRepo.findIncompleteEvents();
    }
  }
  </code></pre>
  
  <p>It apears though that even though I have defined what the generic type is on the event repository the method findIncompleteEvents is not able to resolve the generic declaration with #{#entityName} basicly it returns both the CancelEvent and the AcceptEvent</p>
  
  <p>Now my question:</p>
  
  <p>Is there a way to express what I want without writing 10 different reposities for each subclass of the BaseEvent ?</p>