Hibernate paging question

Discussions

General J2EE: Hibernate paging question

  1. Hibernate paging question (1 messages)

    Hi,
    I'm wondering how the hibernate paging working.
    let's say I have a big result(10000 rows) need to be paged.there are functions like setFirstResult(0), setMaxResults(9) in hibernate,

    hibernate will
    1. only retrieve 10 rows from database, or
    2. retrieve 10000 rows and put to a collection,then filter out first 10 rows from the collection.


    if Hibernate use the 2nd way, it's still take time for each page even there is only few rows on each page

    I use hibernate with Oracle,the genarated sql like:

    select * from (
    select
    id ,
    col1,
    col2,
    from
    theTable
    ) where rownum <= ?

    this is reasonable since Oracle has rownum.
    what if others database(for ex. MS SQL server) doesn't have the similar function?

    please explain.
    thank you

    Joh

    Threaded Messages (1)

  2. Hibernate paging question[ Go to top ]

    Hibernate will use either :

    - SQL possibility : like you see in Oracle (and in most database), Hibernate will generate SQL that do the paging.

    - In a database without it, Hibernate will use a ScrollableResultSet to jump directly to the first result, iterate 10 times and returns.

    - If your database is really dumb and don't support the two previous method, it will iterate all result until the first row asked.

    But it you ask for the 10 first line, it will never iterator the remaining result.

      Adrien