How do I Return SUM from JPA Query Using Hibernate and Spring-boot?

后端 未结 2 850
一向
一向 2021-01-13 21:59

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:<

相关标签:
2条回答
  • 2021-01-13 22:34

    It's not a valid JPQL.

    You either should have:

    @Query("SELECT SUM(m.totalDays) FROM MyEntity m")

    or, make it a native one:

    @Query(value = "SELECT SUM(total_days) FROM MyEntity", nativeQuery = true)

    0 讨论(0)
  • 2021-01-13 22:34

    change your JPQL to @Query("SELECT SUM(m.totalDays) FROM MyEntity m")

    0 讨论(0)
提交回复
热议问题