title: Returning a Collection with Generic Projections so multiple Projections can be selected in Spring Data JPA
body: <p>I am trying to be able to select from multiple projections as return type in a collection when accessing a method in a jpa repository</p>
  <p>I have come across this thread, however its information is not really sufficient:
  <a href="https://stackoverflow.com/questions/48441324/spring-data-jpa-generic-projection-findall">Spring Data Jpa generic projection findAll</a></p>
  <p>It seems like i cant use a list, but i dont understand why and its not explained in that thread.</p>
  <p>I want to get the following code to work:</p>
  <pre><code>public interface ThemingRepository extends JpaRepository&lt;ThemeData, Long&gt; {
    &lt;T&gt; List&lt;T&gt; findByOrderByIdAsc(Class&lt;T&gt; type);
  }
  
    @Transactional
    public byte[] findBackgroundImage() {
  
      var list = themingRepository.findByOrderByIdAsc(ThemeDataBackgroundImage.class);
      if (list.isEmpty()) {
        throw new NoThemeColorsSetException();
      }
      return list.get(0).getBackgroundImage();
    }
  
    @Transactional
    public byte[] findLogoImage() {
  
      var list = themingRepository.findByOrderByIdAsc(ThemeDataLogoImage.class);
      if (list.isEmpty()) {
        throw new NoThemeColorsSetException();
      }
      return list.get(0).getLogo();
    }
  
    @Transactional
    public ThemeDataColors findThemeColors() {
  
      var list = themingRepository.findByOrderByIdAsc(ThemeDataColors.class);
      if (list.isEmpty()) {
        throw new NoThemeColorsSetException();
      }
      return list.get(0);
    }
  </code></pre>
  <p>An example projection:</p>
  <pre><code>public interface ThemeDataBackgroundImage {
    byte[] getBackgroundImage();
  }
  </code></pre>