Spring CRUD repository: is there findOneByMaxXYZColumn()?

You could use limiting in combination with sorting (spring data reference:limit query results). Declare a method similar to the following in your CrudRepository interface :

RetainInfo findTopByCountryOrderByRetVersionDesc(String country);

You can also use findFirst to get the first result. Before getting the result, make sure to use Orderby and then the ascending(Asc) or descending(Desc). As an example if you want to order by version and retrieve based on productName

RetainInfo findFirstByProductNameOrderByVersionDesc(String productName);

Spring Data doesn't provide an expression to select a max value. All supported query parts could be found in the Spring 1.2.0.RELEASE docs: Appendix A. Namespace reference or line 182 of org.springframework.data.repository.query.parser.Part.

Also feel free to create a feature request at Spring's Jira page.

Tags:

Spring Data