The blog for hints & tips about Oracle Application Development Framework and Mobile Application Framework

  • ADFm
    March 27, 2011

Implementing Query pagination using EJB and ADF

Frank Nimphius
Master Principal Product Manager

With pagination, data is queried on demand instead of all –at-once and ad-hoc. It’s a desirable feature especially when working with large data sets to query, e.g. through scrolling in a table. ADF Code Corner (http://www.oracle.com/technetwork/developer-tools/adf/learnmore/index-101235.html) sample #37 explains how to enable query pagination for ADF models that are based on a POJO data model using the JavaBean Data Control. But how do you enable pagination for Enterprise JavaBean models that use the EJB Data Control? The good news is that you don't need to do anything if you started developing your EJB model and ADF applications with Oracle JDeveloper 11g release (PS2) or later.

If you generated the EJB session façade with one of these Oracle JDeveloper, then the following method is automatically added:

public Object queryByRange(String jpqlStmt, int firstResult,
                           int maxResults) {               
  Query query = em.createQuery(jpqlStmt);
  if (firstResult > 0) {
    query = query.setFirstResult(firstResult);
  if (maxResults > 0) {
    query = query.setMaxResults(maxResults);
  return new ArrayList<Employees>(); query.getResultList();

Note This method is also defined in the EJB local and remote interface definition.

When generating the Oracle ADF Data Control configuration for the EJB session façade by right mouse clicking on the class in the JDeveloper Application Navigator and choosing Create Data Control from the context menu, the DataControls.dcx file gets created. The DataControls.dcx file describes the EJB session façade and its interfaces for the generic Data Control class to use. One information it contains is the definition of the DataControlHandler property:


The DataControlHander definition, if set to JPQLDataFilterHandler, ensures that the EJB access uses pagination of the ELB interfaces and the session façade contain the queryByRange method.

For existing, pre Oracle JDeveloper 11.1.13 or non-Oracle JDeveloper created EJB session facades, you can add pagination support by adding the JPQLDataFilterHandler configuration in the DataControls.dcx file and the queryByRange method entries in the EJB interfaces and session façade after upgrading to a recent version of Oracle JDeveloper.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.