I want to return event count by date.Below is my code
@Query(value = "select DATE(e.startTime) as day,count(distinct e.id) as eventCount from events e " +
"where e.clientId=:clientId and e.startTime>=:firstDay and e.startTime<=:lastDay group by DATE(e.startTime)",nativeQuery = true)
Map<Integer, Integer> getClientEventsCountByDay(@Param(value = "clientId") Integer clientId,
@Param(value = "firstDay") String firstDay,
@Param(value = "lastDay") String lastDay);
Input is clientId=2510,firstDay=2019-01-01,lastDay=2019-01-31
This query is throwing below error
Caused by: org.springframework.dao.IncorrectResultSizeDataAccessException: result returns more than one elements; nested exception is javax.persistence.NonUniqueResultException: result returns more than one elements
However this query is working fine when running directly on db.
Try changing to this
List<Map<Integer, Integer>> getClientEventsCountByDay(@Param(value = "clientId") Integer clientId,
@Param(value = "firstDay") String firstDay,
@Param(value = "lastDay") String lastDay);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.