Advertise with us

Our eBooks

How to limit the number of records in a Query with EJB 3.0 ?

 

Use the setMaxResults method from the Java persistence API Query

Example:

@PersistenceContext(unitName="myPersistenceUnit")
   private EntityManager em;

   private int maxRecords = 100;
  
   public void getNextItems() {
        Query q = em.createQuery("select object(o) from Item as o");
        q.setMaxResults(maxRecords);
        items= q.getResultList();
   }

 

© 2021 mastertheboss.com. All Rights Reserved.

Please publish modules in offcanvas position.