For example I need show statistic table on web page. This table consists of 5 rows:
AVG-rating | 5
TotalSum | 12.1
SumToday | 2.1
SummMonth | 8.6
SomeElse | 666
Each value in this table - calculated using an aggregate function in a database.
Question: How is more correct to get this data with spring-data-jpa
?
Now I have One service - StatisticService
with public methos getStatistic(user);
In this method I call 5 methods
from repository
for each statistic value and form response. Each repository method - native query
.
I do not like this aproach. And I think best way is create View
in database
and select all statistic in one query to view.
But this aproach I do not like too. Because I'm tied to the base. and the base contains logic. Although in the first case I use native queries, but I can rewrite them to JPQL
(but maybe not all).
How to more correctly extract aggregated information from the database with spring-data-jpa
?