title: Using Spring JPA Projection with JHipster
body: <p>I'm having some difficulties to use <a href="https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#projections" rel="nofollow noreferrer">Spring Data JPA Projections</a> in a project generated with <a href="https://www.jhipster.tech/" rel="nofollow noreferrer">JHipster</a> version 4.14.5.</p>
  
  <p>I'm following Spring's orientation on how to make projections using JPA respositories, however I'm not having any success. The repo give me <code>null</code> values when I try to use projections.</p>
  
  <p>Since I'm not a big <em>connoisseur</em> of JHipster's pipes, I hope somebody out there may help me out.
  My Entity</p>
  
  <pre><code>@Entity
  @Table(name = "research")
  @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
  public class Research implements Serializable {
  
  private static final long serialVersionUID = 1L;
  
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Long id;
  
  @NotNull
  @Column(name = "answer", nullable = false)
  private String answer;
  
  @OneToOne(optional = false)
  @NotNull
  @JoinColumn()
  private Question question;
  // getters and setters
  </code></pre>
  
  <p>Entity projection:</p>
  
  <pre><code>public interface ResearchSimple {
      Long getId();
      String getAnswer();
  }
  </code></pre>
  
  <p>Entity's repo:</p>
  
  <pre><code>@Repository
  public interface ResearchRepository
  extends JpaRepository&lt;Research, Long&gt; {
      @Query("SELECT r FROM Research r)
      List&lt;ResearchSimple&gt; findAllAsSimple();
  }
  </code></pre>
  
  <p>Test Results</p>
  
  <pre><code>List&lt;ResearchSimple&gt; result = repo.findAllAsSimple();
  assertEquals(result.size, dbSize); // OK
  ResearchSimple simple = result.get(0);
  assertNotNull(simple); // OK
  assertNotNull(simple.getId); // FAIL!
  assertNotNull(simple.getAnswer); // FAIL!
  </code></pre>
  
  <p>Debugging the value obtained in <code>simple</code> I've noticed that the projection was made, but I can't access it's value. Notice that the class <code>br.com.pixinside.projection.ResearchSimple</code> is present in <code>simple</code>'s <code>advised</code>.</p>
  
  <pre><code>org.springframework.aop.framework.ProxyFactory: 2 interfaces    [br.com.pixinside.projection.ResearchSimple, org.springframework.data.projection.TargetAware]; 3 advisors [org.springframework.aop.support.DefaultPointcutAdvisor: pointcut [Pointcut.TRUE]; advice [org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor@1d62a0b], org.springframework.aop.support.DefaultPointcutAdvisor: pointcut [Pointcut.TRUE]; advice [org.springframework.data.projection.ProxyProjectionFactory$TargetAwareMethodInterceptor@3b89f41a], org.springframework.aop.support.DefaultPointcutAdvisor: pointcut [Pointcut.TRUE]; advice [org.springframework.data.projection.ProjectingMethodInterceptor@198453c9]]; targetSource [SingletonTargetSource for target object [org.springframework.data.jpa.repository.query.AbstractJpaQuery$TupleConverter$TupleBackedMap@319267ad]]; proxyTargetClass=false; optimize=false; opaque=true; exposeProxy=false; frozen=false
  </code></pre>