Supported Keywords in Derived Queries

Learn about the keywords supported by the Spring Data Framework for prefixing the method names in derived queries.

The following is the list of supported keywords for prefix in the derived query method name.

Table 1-6 Supported Keywords for Prefix

Prefix Keyword Example
findBy List<Customer> findByFirstName(String firstName)
queryBy List<Customer> queryByFirstName(String firstName)
getBy List<Customer> getByFirstName(String firstName)
readBy List<Customer> readByFirstName(String firstName)
countBy long countByFirstName(String firstName) - returns the count of the matching rows
existsBy boolean existsByLastName(String lastname) - returns true if returned rows > 0

The following is the list of supported keywords for body in the derived query method name.

Table 1-7 Supported Keywords for Body

Body Keyword No. of Parts No. of Params Example
fieldname 1 1 List<Customer> findByLastName(String lastName)
fieldnameReferencefieldname 1 1

List<Customer> findByAddressCity(String city)

class Customer { Address adress; ...}

class Address { String city; ...}

And 2 0 List<Customer> findByFirstNameAndLastName(String firstName, String lastName)
Or 2 0 List<Customer> findByFirstNameOrLastName(String firstName, String lastName
GreaterThan 1 1 List<Customer> findByAgeGreaterThan(int minAge)
GreaterThanEqual 1 1 List<Customer> findByAgeGreaterThanEqual(int minAge)
LessThan 1 1 List<Customer> findByAgeLessThan(int maxAge)
LessThanEqual 1 1 List<Customer> findByAgeLessThanEqual(int maxAge)
IsTrue 1 0 List<Customer> findByVanillaIsTrue()
Desc 1 0 List<Customer> queryByLastNameOrderByFirstNameDesc(String lastname)
Asc 1 0 List<Customer> getByLastNameOrderByFirstNameAsc(String lastname)
In 1 1 List<Customer> findByAddressCityIn(List<Object> cities) - param must be a List
NotIn 1 1 List<Customer> findByAddressCityNotIn(List<String> cities) - param must be a List
Between 2 2 List<Customer> findByKidsBetween(int min, int max)
Regex 1 1 List<Customer> findByFirstNameRegex(String regex)
Exists 1 0 List<Customer> findByAddressCityExists() - find all that have a city set
Near 1 1 List<Customer> findByAddressGeoJsonPointNear(Circle circle) - param must be of org.springframework.data.geo.Circle type
Within 1 1 List<Customer> findByAddressGeoJsonPointWithin(Polygon point) - param must be of org.springframework.data.geo.Polygon type
IgnoreCase 1 0 List<Customer> findByLastNameAndFirstNameIgnoreCase(String lastname, String firstname); -Enable ignore case only for firstName field
AllIgnoreCase many 0 List<Customer> findByLastNameAndFirstNameAllIgnoreCase(String lastname, String firstname); - Enable ignore case for all suitable properties
Distinct 0 0 List<CustomerView> findAllDistinctByLastName(String lastName); - Projection to interface CustomerView List<CustomerProjection> getAllDistinctByLastName(String lastName); - Projection to POJO class CustomerProjection