0

I have a table with below data.

Name    Version
----    -------
ABC      1.0
ABC      1.1
BCD      1.0
BCD      1.1
BCD      1.2

and I am trying to write a spring data jpa findBy method to query all names with latest versions. So my result should be

Name     Version
----     -------
ABC      1.1
BCD      1.2

I tried

findByTopVersionDesc
findByDistinctTopNameDescVersionDesc
findByFirstNameDescVersionDesc

and other combinations but couldn't make this work. Any suggestions

user09
  • 920
  • 2
  • 12
  • 38
  • 1
    I don't think that you can do that with just declaring a method. How would you do that with SQL? – Simon Martinelli Aug 06 '18 at 17:09
  • @Query(value = "select d.name, d.version from entity d inner join (select distinct name, MAX(version) as version from entity group by name) as a on d.name = a.name where d.version = a.version", nativeQuery = true) List findLatestDomainInstances(); it has been written with nativequery. Now we want to return page object and trying to utilize datarest with pagingandsorting repository. While doing, Spring doesn't support paging with Native query as per some other sources in google and I am trying to write this query using findBy method – user09 Aug 06 '18 at 19:19
  • Looking at this answer https://stackoverflow.com/questions/38349930/spring-data-and-native-query-with-pagination it seems pagination is supported with native queries. – mp31415 Aug 06 '18 at 19:48

1 Answers1

0

Probably the way you are writing the method name is wrong:

Spring Docs for what you are trying to do