how to get fixed results using JPA

Hi

I have a table with lot of rows, when I querry, it is taking a lot of time and I am displaying that many rows in UI in single table. So it is not scaling well.

SO I am planing to show x number of row in on page. So for that to achieve, how do I querry the db (derby) using JPA to get first 25 rows, next 25 rows...

I appricate any help

thanks

[377 byte] By [vpalkondaa] at [2007-11-27 4:38:58]
# 1

i think you can have a serial number column in your table and you keep track of that serial number. I mean pass it to your method along with the size of page. Lets say if the number starts from 0 then you can calculate the first page using starting number + page size, if your page size is 25 then you will get 0+25 =25 and you can use the result to query from database like;

select * from myTable where rowNo<=25

You can store this number (Now 25) in user's session and pass it to the method.

Javasa at 2007-7-12 9:49:29 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2
The Query interface defines two methods setMaxResults() and setFirstResult() for this purpose.
Mahesh.Kannana at 2007-7-12 9:49:29 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
thanks to both of you.If I set the max size to query results, how do I get the next set of 25 results? thanks
vpalkondaa at 2007-7-12 9:49:29 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4

in that case u need to set setFirstResult() and then setMaxReults() to the page size.

supppose u have 100 entries and u want only twenty five

in the first request:

setFirstResult(0);

setMaxResults(25);

in the second request:

setFirstResult(25);

setMaxResults(25); //Need to have this pagination logic in UI side

I think this will solve your problem

amarpolimeraa at 2007-7-12 9:49:29 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...