Skip to content

Latest commit

 

History

History

HibernateSpringBootLimitResultSizeViaQueryCreator

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

How To Use Query Creation Mechanism For JPA To Limit Result Size

Description: Spring Data comes with the query creation mechanism for JPA that is capable to interpret a query method name and convert it into a SQL query. This is possible as long as we respect the naming conventions of this mechanism. This is an application that exploit this mechanism to write queries that limit the result size. Basically, the name of the query method instructs Spring Data how to add the LIMIT clause to the generated SQL queries.

Key points:
- define a Spring Data classic repository (e.g., AuthorRepository)
- write query methods respecting the query creation mechanism for JPA naming conventions
- populate the database with some records, in this case via, data-mysql.sql file
- run the queries and check the output sample below

Output example:


You may like to try as well: