title: spring data jpa - class based projections with custom query
body: <p>I need to have a spring data repository method for a custom query and would like to use class based projection.</p>
  
  <p>Looking at this 
  <a href="https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#projections" rel="noreferrer">https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#projections</a></p>
  
  <pre><code>@Entity
  public class Person {
    @Id
    private Long id;
    private String firstName;
    private String lastName;
    private int age;
  }
  
  @Value // lombok annotation to create constructor, equals and hash-code
  public class PersonDTO {
    private String firstName;
    private String lastName;
  }
  
  public interface PersonRepository extends Repository&lt;Person, Long&gt; {
  
  List&lt;PersonProjection&gt; findDistinct();
  
  @Query("select distinct firstName, lastName from Person")
  List&lt;PersonProjection&gt; findDistinctQuery();
  
  @Query(value = "select distinct first_name, last_name from person", nativeQuery = true)
  List&lt;PersonProjection&gt; findDistinctNativeQuery();
  
  }
  </code></pre>
  
  <ul>
  <li>findDistinct works well</li>
  <li>findDistinctQuery and findDistinctNativeQuery throw</li>
  </ul>
  
  <blockquote>
    <p>No converter found capable of converting from type
    [org.springframework.data.jpa.repository.query.AbstractJpaQuery$TupleConverter$TupleBackedMap]
    to type [com.x.PersonDTO]</p>
  </blockquote>
  
  <p>Is there any option to make it work with classes (not interfaces)?</p>