title: Spring Data JPA mapping nested entities
body: <p>I'm a little bit confused about using projections in Spring Data JPA.
  I wanted to optimize my queries by <strong>requesting only needed columns (preferably) in one query</strong>, and I thought that using projections is a good idea. But it seems that projection with nested projection becomes open and requests all columns and further nesting is impossible.</p>
  
  <p>I've tried to find a solution with <code>@Query</code> (cannot find how to map nested lists), <code>@EntityGraph</code> (cannot find how to request only specified column) and <code>@SqlResultSetMapping</code> (cannot find how to make mapping nested lists), but it hasn't worked for me.
  Is there any solution except receiving <code>List&lt;Object[]&gt;</code> and manually mapping?</p>
  
  <p>I have the next entities classes (simplified for the question):</p>
  
  <pre><code>public class TestAttempt{
      private Long id;
      private User targetUser;
      private Test test;
  }
  
  public class Test{
      private Long id;
      private String name;
      private Set&lt;Question&gt; questions;
  }
  
  public class Question{
      private Long id;
      private String name;
      private Test test;
  }
  </code></pre>
  
  <p>And I wanted to write something like this (it can be just <code>TestAttempt</code> with <code>null</code> in unused fields):</p>
  
  <pre><code>public interface TestAttemptList {
      Long getId();
      Test getTest();
  
      interface Test {
          String getName();
  
          List&lt;Question&gt; getQuestions();
  
          interface Question {
              String getName();
          }
      }
  }
  
  public interface TestAttemptRepository extends JpaRepository&lt;TestAttempt, Long&gt; {
      List&lt;TestAttemptList&gt; getAllByTargetUserId(Long targetUserId);
  }
  </code></pre>
  
  <p>And in result get something like this:</p>
  
  <pre><code>{
      id: 1,
      test: {
          name: test1,
          questions: [{
              name: quest1
          }, {
              name: quest2
          }]
      }
  }
  </code></pre>