title: Return a DTO Object in spring data repository method annotated with @Query
body: <p>I have a Repository  and in this interface I have a method that would like to return a ComentarioEditalDto instead of an ComentarioEdital, but when I call this method an exception is thrown, telling me that I don't have a Converter, how can I convert to return a instance of another class?.</p>
  
  <pre><code>import br.edu.ifrn.rederenova.dto.ComentarioEditalDto;
  import br.edu.ifrn.rederenova.model.ComentarioEdital;
  import java.util.List;
  import org.springframework.data.jpa.repository.Query;
  import org.springframework.data.repository.CrudRepository;
  import org.springframework.data.repository.query.Param;
  import org.springframework.stereotype.Repository;
  
  @Repository
  public interface ComentarioRepository extends CrudRepository&lt;ComentarioEdital, Long&gt;{
  
      @Query(value = "SELECT c.id, c.texto, c.data_ultima_edicao, c.autor_id, " +
             "c.data_criacao, c.edital_id, c.excluida FROM comentario_edital c INNER JOIN edital e ON e.id = c.edital_id " +
             "WHERE (c.excluida = FALSE OR c.excluida IS NULL) AND e.numero = :numero ORDER BY c.data_criacao DESC",
              nativeQuery = true)
      public List&lt;ComentarioEditalDto&gt; findAllByEdital(@Param("numero") String nuEdital);
  
  }
  </code></pre>
  
  <p>I removed Gets and Sets</p>
  
  <pre><code>import br.edu.ifrn.rederenova.model.ComentarioEdital;
  import br.edu.ifrn.rederenova.model.Edital;
  import br.edu.ifrn.rederenova.model.Usuario;
  import java.util.Calendar;
  import java.util.List;
  
  public class ComentarioEditalDto {
  
      private Long id;
      private String texto;
      private Calendar dataCriacao;
      private Calendar dataUltimaEdicao;
      private List&lt;ComentarioEdital&gt; respostasComentario;
      private Usuario autor;
      private Edital edital;
      private Boolean excluida;
  
  }
  </code></pre>
  
  <p>I removed Gets and Set</p>
  
  <pre><code>import com.fasterxml.jackson.annotation.JsonIgnore;
  import java.io.Serializable;
  import java.util.Calendar;
  import java.util.List;
  import java.util.Objects;
  import javax.persistence.CascadeType;
  import javax.persistence.Entity;
  import javax.persistence.FetchType;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.JoinColumn;
  import javax.persistence.JoinTable;
  import javax.persistence.ManyToOne;
  import javax.persistence.OneToMany;
  import javax.persistence.SequenceGenerator;
  import javax.persistence.Temporal;
  import javax.persistence.TemporalType;
  import javax.validation.constraints.NotBlank;
  import org.springframework.format.annotation.DateTimeFormat;
  
  @Entity
  @SequenceGenerator(allocationSize = 1, initialValue = 1, name = "comentario_seq", sequenceName = "comentario_seq")
  public class ComentarioEdital implements Serializable {
  
      @Id
      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "comentario_seq")
      private Long id;
      @NotBlank(message = "Não deve estar vazio")
      private String texto;
      @Temporal(TemporalType.TIMESTAMP)
      @DateTimeFormat(pattern = "dd/MM/yyyy")
      private Calendar dataCriacao;
      @Temporal(TemporalType.TIMESTAMP)
      @DateTimeFormat(pattern = "dd/MM/yyyy")
      private Calendar dataUltimaEdicao;
      @OneToMany(cascade = {CascadeType.REMOVE, CascadeType.REFRESH}, fetch = FetchType.EAGER)
      @JoinTable(name = "respostas_comentario",
                  joinColumns = @JoinColumn(name = "pergunta_id"),
                  inverseJoinColumns = @JoinColumn(name = "resposta_id"))
      private List&lt;ComentarioEdital&gt; respostasComentario;
      @ManyToOne(fetch = FetchType.EAGER)
      private Usuario autor;
      @JsonIgnore
      @ManyToOne(fetch = FetchType.LAZY)
      private Edital edital;
      @JsonIgnore
      private Boolean excluida;
  }
  </code></pre>
  
  <p>A little of the exception</p>
  
  <blockquote>
    <p>org.springframework.core.convert.ConverterNotFoundException: No
    converter found capable of converting from type
    [org.springframework.data.jpa.repository.query.AbstractJpaQuery$TupleConverter$TupleBackedMap]
    to type [br.edu.ifrn.rederenova.dto.ComentarioEditalDto]  at
    org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:321)
    ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]    at
    org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:194)
    ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]</p>
  </blockquote>