0

I am using Spring Boot 2.5.0 for one of my test projects and need to get some data from one of the transaction tables. I need only latest record per group from this table. This problem has a solution given multiple times on SO, one of which is https://stackoverflow.com/a/1313293/841221.

However, I want to implement the same using Spring Boot Data JPA and not using a native query as using a native query would make me lose database independence.

Can someone please help me?

Aakash
  • 2,029
  • 14
  • 22
  • Would this help? https://stackoverflow.com/questions/52744463/how-to-select-latest-record-in-group-using-jpql-in-spring-jparepository – pleft Aug 29 '21 at 14:28
  • thank yuo @pleft for suggestion, but this needs a native query that I would like to avoid, to still be database independent. – Aakash Aug 29 '21 at 15:06
  • Native? I dont see native queries in `@Query` statements in the accepted answer there :( https://stackoverflow.com/a/52960779/3635454 – pleft Aug 29 '21 at 15:08
  • you can use custom repository implementation and write your own query using `jpql` => `SELECT t.name, MAX(t.id) FROM Transaction t GROUP BY t.name` – Olivier Boissé Aug 29 '21 at 15:50
  • how does the transaction table look like ? is there a lastUpdated column or anything of the sort ? – loser8 Aug 29 '21 at 15:58

0 Answers0