title: Two different queries returning the same object Spring Boot JPA
body: <p>I created a Repository with 3 different queries. Each query returns a different result. But when it comes to mapping the first query result goes to the second query result. If I change the order of the queries the first result will be the result of the next query. I even tried to create two different Repositories</p>
  <p>These are the result objects query:
  <a href="https://i.stack.imgur.com/zTP9T.png" rel="nofollow noreferrer">First Result</a>
  <a href="https://i.stack.imgur.com/S7nc2.png" rel="nofollow noreferrer">Second Result</a></p>
  <p>This is my First repository:</p>
  <pre><code>package com.springboot.first.app;
  
  
  @Repository
  public interface TotalSRepository extends JpaRepository&lt;TotalEntity, Date&gt;{
  
  
  @Query(value= &quot;select `data` , SUM(importo) as totaleContanti, 0 AS totaleBanca from spese s where (dataAss is null or dataAss &gt; DATE(NOW()) ) and MONTH(s.`data` )= :mese and year(s.`data`) = :anno and s.tipoPag IN('CONTANTI', 'VOUCHER') group by s.`data`&quot;, 
          countQuery = &quot;SELECT count(*) from spese s where (dataAss is null or DATE(NOW()) &gt;= dataAss) and MONTH(s.`data` )= :mese and year(s.`data`) = :anno and s.tipoPag IN('CONTANTI', 'VOUCHER') group by s.`data`&quot;, 
          nativeQuery = true)
          List&lt;TotalEntity&gt; findSpeseTotalsContanti(@Param(&quot;mese&quot;) Integer mese, @Param(&quot;anno&quot;) Integer anno);
  
  @Query(value= &quot;select `data` , SUM(importo) as totaleBanca, 0 AS totaleContanti from spese s where (dataAss is null or dataAss &gt; DATE(NOW()) ) and MONTH(s.`data` )= :mese and year(s.`data`) = :anno and s.tipoPag NOT IN('CONTANTI', 'VOUCHER') group by s.`data`&quot;, 
          countQuery = &quot;SELECT count(*) from spese s where (dataAss is null or DATE(NOW()) &gt;= dataAss ) and MONTH(s.`data` )= :mese and year(s.`data`) = :anno and s.tipoPag NOT IN('CONTANTI', 'VOUCHER') group by s.`data`&quot;, 
          nativeQuery = true)
          List&lt;TotalEntity&gt; findSpeseTotalsBanca(@Param(&quot;mese&quot;) Integer mese, @Param(&quot;anno&quot;) Integer anno);
  
  }
  </code></pre>
  <p>This is the second repo</p>
  <pre><code>@Repository
  public interface TotalRepository extends JpaRepository&lt;TotalEntity, Date&gt;{
  
  @Query(value= &quot;select `data`, (SUM(importoC) + SUM(importoT)) as totaleContanti, SUM(importoP) as totaleBanca from incassi i where MONTH(i.`data`) = :mese and YEAR(i.`data`) = :anno group by i.`data`&quot;, 
          countQuery = &quot;SELECT count(*) from incassi i where MONTH(i.`data`) = :mese and YEAR(i.`data`) = :anno group by i.`data`&quot;, 
          nativeQuery = true)
          List&lt;TotalEntity&gt; findIncassiTotals(@Param(&quot;mese&quot;) Integer mese, @Param(&quot;anno&quot;) Integer anno);
  
  
  }
  </code></pre>
  <p>This is the entity</p>
  <pre><code>@Entity
  public class TotalEntity {
  private Date data;
  private Double totaleBanca; 
  private Double totaleContanti; 
  
  
  public TotalEntity() {
  }
  
  
  @Id
  @Column(name = &quot;data&quot;)
  public Date getData() {
      return data;
  }
  
  public void setData(Date data) {
      this.data = data;
  }
  
  @Basic
  @Column(name = &quot;totalebanca&quot;)
  public double getTotaleBanca() {
      return totaleBanca;
  }
  
  public void setTotaleBanca(double importoC) {
      this.totaleBanca = importoC;
  }
  
  
  @Basic
  @Column(name = &quot;totalecontanti&quot;)
  public double getTotaleContanti() {
      return totaleContanti;
  }
  
  public void setTotaleContanti(double importoC) {
      this.totaleContanti = importoC;
  }
  
  
  
  }
  </code></pre>
  <p>I tried to execute the Hibernate logged query</p>
  <pre><code>Hibernate: select `data`, (SUM(importoC) + SUM(importoT)) as totaleContanti, SUM(importoP) as totaleBanca from incassi i where MONTH(i.`data`) = ? and YEAR(i.`data`) = ? group by i.`data`
  Hibernate: select `data` , SUM(importo) as totaleBanca, 0 AS totaleContanti from spese s where (dataAss is null or dataAss &gt; DATE(NOW()) ) and MONTH(s.`data` )= ? and year(s.`data`) = ? and s.tipoPag NOT IN('CONTANTI', 'VOUCHER') group by s.`data`
  Hibernate: select `data` , SUM(importo) as totaleContanti, 0 AS totaleBanca from spese s where (dataAss is null or dataAss &gt; DATE(NOW()) ) and MONTH(s.`data` )= ? and year(s.`data`) = ? and s.tipoPag IN('CONTANTI', 'VOUCHER') group by s.`data`
  </code></pre>
  <p>and the results are correct. But the mapped object in debug is the same. Any suggestion?</p>