The document describes keywords that can be used inside method names to define queries when using Spring Data JPA. It lists over 30 keywords such as "And", "Or", "Is", "Between", etc. and provides the sample method name and JPQL snippet that would be generated for each keyword. For example, the "And" keyword samples are "findByLastnameAndFirstname" which would generate "where x.lastname = ?1 and x.firstname = ?2". The document provides this mapping for many query keywords to show how to write concise query method names in Spring Data JPA.
The document describes keywords that can be used inside method names to define queries when using Spring Data JPA. It lists over 30 keywords such as "And", "Or", "Is", "Between", etc. and provides the sample method name and JPQL snippet that would be generated for each keyword. For example, the "And" keyword samples are "findByLastnameAndFirstname" which would generate "where x.lastname = ?1 and x.firstname = ?2". The document provides this mapping for many query keywords to show how to write concise query method names in Spring Data JPA.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1
Table 4.
Supported keywords inside method names
Keyword Sample JPQL snippet Java Persistence Query Language And findByLastnameAndFirstname … wherex.lastname = ?1 and x.firstname = ?2 Or findByLastnameOrFirstname … wherex.lastname = ?1 or x.firstname = ?2 Is,Equals findByFirstname,findByFirstnameIs,findByFirstnameEquals … wherex.firstname = ?1 Between findByStartDateBetween … wherex.startDate between ?1 and ?2 LessThan findByAgeLessThan … wherex.age < ?1 LessThanEqual findByAgeLessThanEqual … wherex.age <= ?1 GreaterThan findByAgeGreaterThan … wherex.age > ?1 GreaterThanEqual findByAgeGreaterThanEqual … wherex.age >= ?1 After findByStartDateAfter … wherex.startDate > ?1 Before findByStartDateBefore … wherex.startDate < ?1 IsNull findByAgeIsNull … wherex.age is null IsNotNull,NotNull findByAge(Is)NotNull … wherex.age not null Like findByFirstnameLike … wherex.firstname like ?1 NotLike findByFirstnameNotLike … wherex.firstname not like ?1 StartingWith findByFirstnameStartingWith … wherex.firstname like ?1 (parameter bound with appended %) where x.firstname like ‘?%’ EndingWith findByFirstnameEndingWith … where x.firstname like ?1 (parameter bound with prepended %) where x.firstname like ‘%?’ Containing findByFirstnameContaining … where x.firstname like ?1 (parameter bound wrapped in %) where x.firstname like ‘%?%’ OrderBy findByAgeOrderByLastnameDesc … where x.age = ?1 order by x.lastname desc Not findByLastnameNot … where x.lastname <> ?1 In findByAgeIn(Collection<Age> ages) … where x.age in ?1 NotIn findByAgeNotIn(Collection<Age> age) … where x.age not in ?1 True findByActiveTrue() … where x.active = true False findByActiveFalse() … where x.active = false IgnoreCase findByFirstnameIgnoreCase … where UPPER(x.firstame) = UPPER(?1) First findFirstBy … limit 1 Top findTopBy … limit 1 First findFirst15By … limit 15 Top findTop15By … limit 15 Top findTop20ByOrderByAgeDesc … order by x.age desc limit 20