Home JBoss howto EJB How to paginate your EJB 3.0 ?
30 | 07 | 2010
JBoss 5 AS Book
"JBoss AS 5 development" reviews
Please share your feedback/review with other readers!
Banner
Dashboard
Advertise with Us
Banner
RSS Feed
Java EE 1.6 resources
Login
Sign here for the NewsLetter.



JBoss admin resources
Banner
Java EE 1.6 resources
JBoss howto

How to avoid the 50 seconds start up limit in Eclipse ?

JBoss recipe of the day ...
Read More

How can you solve deployment errors caused by large war/jar/ear files ?

jboss recipe of the day ...
Read More

How do you configure your .war to be deployed after your EJB ?

jboss recipe of the day ...
Read More
How to paginate your EJB 3.0 ?
Written by F.Marchioni   
JBoss recipe of the day

Retrieving a large amount of data and returning them to the client can be quite paniful....however with EJB 3 it's quite easy to paginate a large resultset: for example supposing you want to retrieve only the first "page" of 100 Users:

 

  List <Users> tasklist = em.createNamedQuery("findUsersByRole")
    .setParameter("role", role)
    .setMaxResults(100)
    .setFirstResult(0)
    .getResultList();

You could further optimize the query with "setFetchSize" which  sets a fetch size for the underlying JDBC query.

I have tested with a (rather complex) resultset of 100.000 records on JBoss AS 5.0 + Oracle 10.1. Retrieving the full Resultset took about 12 seconds (not too bad, with plain SQL it took about 7.5 seconds). Retrieving the single page of 100 records took just 0.5 seconds.






JBoss.org Search
Custom Search
Comments
Search
Only registered users can write comments!

3.26 Copyright (C) 2008 Compojoom.com / Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."