title: Spring mongodb projection on repository
body: <p>I Try to use this feature:</p>
  
  <p><a href="http://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#projections" rel="nofollow">http://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#projections</a></p>
  
  <p>So I have one class:</p>
  
  <pre><code>@Document
  public class Ficha {
      @Id
      private String id;
      private Parte parte;
      private String observacao;
      private Integer numero;
      @JsonSerialize(using = LocalDateTimeSerializer.class)
      @JsonDeserialize(using = LocalDateTimeDeserializer.class)
      private LocalDateTime cadastro;
      private String livro;
      private String folha;
      private String papelSeguranca;
      private String selo;
      private Usuario atendente;
      private Escrevente escrevente;
      private Biometria digital;
      private List&lt;Imagem&gt; documentos;
  }
  </code></pre>
  
  <p>Then I create one interface to return only 2 fields:</p>
  
  <pre><code>public interface FichaSemParte {
      Integer getNumero();
      String getLivro();
  }
  </code></pre>
  
  <p>And in my repository I put:</p>
  
  <pre><code>public interface FichaRepository extends CrudRepository&lt;Ficha, String&gt; {
  
      FichaSemParte findFirstByLivro(String livro);
  
  }
  </code></pre>
  
  <p>So now how I convert the return to one <code>Ficha</code>? When I try to use this:</p>
  
  <pre><code>Ficha ficha = (Ficha) myRepo.findFirstByLivro("1")
  </code></pre>
  
  <p>returns this error:</p>
  
  <blockquote>
    <p>java.lang.ClassCastException: com.sun.proxy.$Proxy122 cannot be cast
    to br.com.lumera.cartoriointeligente.entity.Ficha</p>
  </blockquote>