title: How do I Return SUM from JPA Query Using Hibernate and Spring-boot?
body: <p>I am trying to use JPA and JPQL to query my entity and return the sum of a column (total days) from the table.  I thought I had set it up right but I am getting this error:</p>
  
  <pre><code>Caused by: org.springframework.beans.factory.BeanCreationException:
  Error creating bean with name 'myRepository':
  Invocation of init method failed; nested exception is
  java.lang.IllegalArgumentException: Validation failed for query for method
  public abstract java.lang.Float
  com.nissan.rca.repository.MyRepository.selectTotals()!
  </code></pre>
  
  <p>Here is a representation of my entity:</p>
  
  <pre><code>@Entity
  @Table(name = "TABLENAME")
  @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
  public class MyEntity implements Serializable {
  
      private static final long serialVersionUID = 1L;
  
      @EmbeddedId
      private MyEntityCompositeKey myEntityCompositeKey;
  
      @Column(name = "raiser_id")
      private String raiserID;
  
      @Column(name = "total_days")
      private Float totalDays;
  </code></pre>
  
  <p>and here is my repository in which I make the query assigned to a method:</p>
  
  <pre><code>@Repository
  public interface MyRepository extends JpaRepository&lt;MyEntity, ID&gt; {
      @Query("SELECT SUM(total_days) FROM MyEntity")
      Float selectTotals();
  }
  </code></pre>
  
  <p>I call the selectTotals() method from myRepository object in my rest controller for the api mapping.</p>
  
  <pre><code>@GetMapping("/getForecastTotals")
  public Float getForecastTotals() {
      return myRepository.selectTotals();
  }
  </code></pre>
  
  <p>I'm unsure as to why it can't be returned as a float.</p>