我正在尝试使用JPA和JPQL查询实体并从表格中返回一列的总和(总天数)。我认为我已经正确地设置了它,但是我收到了这个错误:
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()!
这是我的实体的表示:
@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;
这里是我的存储库,在其中我将查询指定给一个方法:
Translated:这里是我的存储库,在其中我将查询指定给一个方法:
@Repository
public interface MyRepository extends JpaRepository<MyEntity, ID> {
@Query("SELECT SUM(total_days) FROM MyEntity")
Float selectTotals();
}
我在我的rest controller中为api映射从myRepository对象调用selectTotals()方法。
@GetMapping("/getForecastTotals")
public Float getForecastTotals() {
return myRepository.selectTotals();
}
我不确定为什么它不能作为浮点数返回。