Spring Data: JPA repository return Map instead of List?

I have such Query where from which I want to extract movie title and its rating

   @Query(value ="SELECT m.title, r.avg(rating) " +
        "FROM movies m " +
        "INNER JOIN " +
        "ratings r " +
        "ON m.movieid = r.movieid " +
        "WHERE m.genre = LIKE %:genre% " +
        "GROUP BY r.avg(rating) " +
        "ORDER BY r.avg(rating) DESC " +
        "LIMIT 10",
        nativeQuery = true)
 List<Movies> topTenMoviesByGenreLikeIgnoreCase(@Param("genre") String genre);

But this list obviously cannot store the resultSet with 2 values

After learning about it I've found e.g. this link Spring Data: JPA repository findAll() to return *Map instead of List? but their implementation seems unclear to me.

I don't understand where do they get the Long value from in the first link

default Map<Long, TransactionModel> findByClientIdMap(Long id) {
    return findByClientId(id).stream().collect(Collectors.toMap(TransactionModel::getId, v -> v));

How do I create my map?

default Map<Movies, Float> topTenMoviesByGenreLikeIgnoreCaseMap(@Param("genre") String genre) {
    return topTenMoviesByGenreLikeIgnoreCase(genre).stream().collect(Collectors.toMap());

Read more here: https://stackoverflow.com/questions/65725314/spring-data-jpa-repository-return-map-instead-of-list

Content Attribution

This content was originally published by 63350541 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: