Results 1 to 6 of 6

Thread: limiting results in Hibernate?

  1. #1
    Join Date
    Jun 2005
    Location
    Philly
    Posts
    199

    Default limiting results in Hibernate?

    How do I return result 0-25, 26-50, 51-75 etc....

  2. #2
    Join Date
    Aug 2004
    Location
    Southampton, UK
    Posts
    826

    Default

    Check out the Hibernate JavaDocs for the Query interface - it talks about paging using setMaxResults and setFirstResult.

    Rob
    Rob Harrop
    Lead Engineer, dm Server
    SpringSource
    http://www.springsource.com

    Co-Author - Pro Spring

  3. #3
    Join Date
    Nov 2004
    Location
    Hilversum - The Netherlands
    Posts
    1,054

    Default

    Watch out for crappy database queries. Hibernate translates pagination for Ms Sql to a select top query. So if you need 9.900 to 10.000 you will get 10.000 records and not 100. This could be a serious performance problem.

  4. #4
    Join Date
    Jun 2005
    Location
    Philly
    Posts
    199

    Default

    But what on the HibernateTemplate am I suppose to use?
    I am using Hibernate solely through the Spring Hibernate templates.

    Quote Originally Posted by robh
    Check out the Hibernate JavaDocs for the Query interface - it talks about paging using setMaxResults and setFirstResult.

    Rob

  5. #5
    Join Date
    Nov 2004
    Location
    Hilversum - The Netherlands
    Posts
    1,054

    Default

    Quote Originally Posted by mickknutson
    But what on the HibernateTemplate am I suppose to use?
    I am using Hibernate solely through the Spring Hibernate templates.
    You have to create a session somewhere so you can create a Criteria/Query/SqlQuery that can be executed to retrieve the information.


    For more information see:
    http://www.hibernate.org/hib_docs/ap.../Criteria.html

    And check the
    setMaxResults(int maxResults)
    setFirstResult(int firstResult)

    to use pagination.

  6. #6
    Join Date
    Jul 2005
    Location
    Maryland
    Posts
    40

    Default

    Read the following section of the Spring reference guide:

    11.2.3. Inversion of Control: HibernateTemplate and HibernateCallback

    http://static.springframework.org/sp...m.html#d0e6874

Similar Threads

  1. Replies: 5
    Last Post: Dec 27th, 2005, 07:00 AM
  2. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM
  3. Replies: 3
    Last Post: Nov 19th, 2004, 07:16 PM
  4. Replies: 9
    Last Post: Sep 25th, 2004, 12:35 PM
  5. Replies: 7
    Last Post: Aug 21st, 2004, 03:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •