JPA setMaxResults Example

Advertisement

In this section, you will learn how to use the setMaxResults() method in your JPA application.

JPA setMaxResults Example

In this section, you will learn how to use the setMaxResults()
method in your JPA application. The setMaxResults function is used to
set a limit to restrict the number of objects returned from database.

setMaxResults(int maxResult): This method is
used with query instance for setting the maximum number of results to be fetched
from database.

To test the setMaxResults with example follow
the following steps:

Database Table: student, create student
table.

Model Class: Student.java, develop the model
class.

Main Class: JPASetMaxResult.java, develop the
program to run the application.