Java – Spring data query with max limit and condition

javaspringspring-dataspring-data-jpa

I want to get the item with the highest year and has a particular personal name. I'm trying this:

Foo findTopByOrderByYearDesc();

This work great, the problem is when I add a new param to filter results

Foo findTopByOrderByYearDescAndPersonName(@Param("person.name") final String name);

But I get this error:

No property andPersonName found for type Foo!

I try this too but I get de same error:

Foo findTopByOrderByYearDescByPersonName(@Param("person.name") final String name);

Best Answer

You should use the following:

Foo findTopByPersonNameOrderByYearDesc(@Param("person.name") final String name);

The first 'by' keyqord works as a delimiter see here