0

I have a order fulfillment application mostly made with Spring Data Rest and spring boot. I need to get every product, find them in orders and calculate how many sold in total and what the price is in a given time period. I have other requirements like this.

Now the data represented in the report will not be like any of the business entities. It will have sums, totals, a field from one entity, a field from another entity... And it will not be persisted it will be generated only for the client to consume. It should be pageable too.

What is the correct approach to tackle this? Do I use pojos to represent the report lines? How do I manage paging with this? Does it make sense to have a repository for each report? Is it possible with hql to return a report line that is not a persisted entity from a repository method?

aycanadal
  • 1,106
  • 2
  • 15
  • 42
  • 1
    I would recommend to perform such complex queries on pure SQL and map them to DTO object (`JdbcTemplate` can be used). Pagination can also be easily done with SQL queries. Hence your coding part can be more annoying, but the performance will not suffer. – J-Alex Jul 11 '17 at 15:23
  • I think you are giving to little information about the problem, how much data are you talking about, how complicated are the queries, how much time you have to process the reports. And one thing its the persistence layer, other the business one to deal with the calc, and other the presentation layer to deal with the report. – nekperu15739 Jul 11 '17 at 15:47
  • Not too much information and not too complicated. Maybe one or two more reports like the one I mentioned. – aycanadal Jul 11 '17 at 16:14
  • JdbcTemplate was what I was looking for. If you add as answer I will accept thank you. – aycanadal Jul 18 '17 at 14:37
  • I prepare a [howto](https://stackoverflow.com/q/45401734) about dealing with DTO in SDR projects. Don't forget to upvote it if it will be helpful... – Cepr0 Jul 30 '17 at 15:57

0 Answers0