I am working on a Spring application and use Spring Data JPA for database manipulation. I have come across a problem with creating a query.
I have a table where users store products. I want to retrieve a Map for a given user, where I will have information about all distinct categories that the given user has his products in, and their count. In native sql that would be the following query :
SELECT category, count(*) FROM products where user_id = 1 GROUP BY category;
Can you help me achieving it in a Spring Data Jpa Repository? How should the @Query look like? And how to return the data as a Map? Thanks!