I created a repository that extends CrudRepository, this repository has a method with @Query notation:
the code:
@Query("select itemType, count(*) as count from Item where User_id = :userId group by itemType")
List<Map<String, Long>> countItemsForUser(@Param("userId") Long userId);
The problem I am facing is that this returns an ArrayList of the object (s), not a list of maps. I read somewhere that JPA cannot return the map, so I find the result in List>.
I do not know how best to get around this problem or quickly access the result data. I tried casting, but that didn't work either:
for(Object item: items) {
Map<String,Long> castedItem = (HashMap<String,Long>)item;
}
source
share