title: Inheritance in HQL with Spring Data JPA
body: <p>I have set of classes which inherit from a single super class:</p>
  
  <pre><code>   Super
       |
       +------+-------+
       Aaaa   Bbbb    Cccc
  </code></pre>
  
  <p>Each of the Aaaa,Bbbb,Cccc then should contain method findByTag. The problem is that I can't manage to define it generally. Following example defines specific findByTag for Aaaa.</p>
  
  <pre><code>public interface AaaaRepository extends SuperRepository&lt;Aaaa&gt; {
      @Query("select distinct a from Aaaa a " +
              "join a.tags t " +
              "join fetch a.locale where t = ?1")
      public List&lt;Event&gt; findByTag(Tag t);
  }
  </code></pre>
  
  <p>Note that the Superclass is @MappedSuperclass and does not have its own table in database.</p>
  
  <p>I would like to use some kind of "Super" in the query which would be replaced in each class by its name.</p>
  
  <p>My second problem is that I don't know how to force @ElementCollection to be Eagerly fetched. I have to always explicitly say "join fetch" in the query. If it is not fetched, once the transaction is finished, I can't access those objects, which I did not explicitly fetched. (LazyFetch Exceptions...)</p>
  
  <p>Thanks</p>