title: How can I improve a JpaRepository slow method performance which has a very fast query(run at PL/SQL developer)?
body: <p>I had this repo (sorry for portuguese words):</p>
  
  <pre><code>public interface EntityARepository extends JpaRepository&lt;EntityA, Long&gt; {
  
    @Query("select new package.someDTO(lan.dataLancamento, lan.prazoVinculado, lan.valor, his.tipo, his.descricao) "
        + "from EntityA lan, EntityB his, EntityC cc "
        + "where lan.conta = cc.idCc "
        + "and   lan.historico = his.idHistorico "
        + "and   lan.dataLancamento &gt;= :presente "
        + "and   lan.dataLancamento &lt;= :futuro "
        + "and   cc.agencia = :agencia "
        + "and   cc.numConta = :conta "
        + "order by lan.dataLancamento asc")
    public List&lt;someDTO&gt; findByAgenciaAndContaEntreDatas(@Param("agencia") Long agencia, @Param("conta") Long conta, @Param("presente") Date presente, @Param("futuro") Date futuro);
  </code></pre>
  
  <p>And this method works, but it takes like 5-6s to return a 3 element list. On PL/SQL Developer, the same query takes 0.015s:</p>
  
  <pre><code>select lan.data_lancamento,
         lan.prazo_vinculacao,
         lan.valor,
         his.tipo_lancamento,
         his.descricao
    from tableA lan, tableB his, tableC cc
   where lan.cc = cc.id_cc
     and lan.historico = his.id_historico
     and lan.data_lancamento &gt;= '17/05/2012'
     and lan.data_lancamento &lt;= '17/08/2012'
     and cc.agencia = 1
     and cc.num_conta = 201243
   order by lan.data_lancamento asc;
  </code></pre>
  
  <p>I'm using a local Oracle database. How could I improve this query to be faster? I thought I could use some <code>nativeQuery = true</code>, but this would stop from using <code>new package.someDTO</code> and since my query mixes data from 2 tables and uses a 3rd to verify some data. I can't create a new repository based on my DTO since it doesn't have any primary key and any unique attribute.</p>