title: Spring Data - get entity name/type from Repository
body: <p>I am looking for a way to get an entity type or class name from an instance implementing Spring Data JPA <code>Repository</code> interface.</p>
  
  <p>I have got a number of interfaces extending a base interface that extends <code>Repository</code> interface and that defines some base queries.</p>
  
  <pre><code>@NoRepositoryBean
  public interface EnumerationRepository&lt;T extends IDatabaseEnumeration&gt; extends Repository&lt;T, String&gt; {
      // ...
  }
  
  public interface SampleEnumerationRepository extends EnumerationRepository&lt;SampleEnumeration&gt; {
  
  }
  </code></pre>
  
  <p>Spring allows me to inject implementations of all these interfaces as a collection into a bean</p>
  
  <pre><code>@Autowired
  private Collection&lt;EnumerationRepository&lt;? extends IDatabaseEnumeration&gt;&gt; repositories;
  </code></pre>
  
  <p>I wanted to put all of these implementations into a <code>Map</code> for an easy access inside a generic method. I wanted to use the entity type or name as the key but I am not sure where to get it. Is there any way to get one of these attributes? Preferably the class type.</p>
  
  <p>I was able to achieve the desired behaviour with a query like this. But I would like to avoid this solution if possible as it creates a dependency on the underlying DB.</p>
  
  <pre><code>@Query(value = "select '#{#entityName}' from dual", nativeQuery = true)
  public String getEntityName();
  </code></pre>