Controlling the number of entities returned by a Select query

In addition to using a Where clause to limit the number of entities returned, there are a couple of other approaches possible. This recipe addresses the use of methods to control the number of entities returned and to specify the first entity of the set to return. This permits us to retrieve the results of a query as a series of subsets.

This technique is useful when we want to display only a subset of entities at a time. By displaying a partial set, the user is not overwhelmed with a long list and a partial list will be returned faster than a complete list.

Getting ready

We will execute a query in the same way as before, but limit the number returned using a combination of Query methods. ...

Get EJB 3.1 Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.