Results 1 to 3 of 3

Thread: problem in setMaxResult

  1. #1

    Default problem in setMaxResult

    Hi,

    I am using Hibernate version:3.0 and I have made a small function in a standalone application to retrieve only some elements from the List in the following manner
    Code:
       public List getAllCustomers() { 
          List customerList = null; 
    
          getHibernateTemplate().setMaxResults(50); 
          customerList = getHibernateTemplate().find("from Customer c where c.password=?", "password"); 
          System.out.println("No. of customers retrieved=" + customerList.size()); 
    
          return customerList; 
       } 

    and it is working absolutely fine and returns only 50 records out of 1000 in the database.

    But when I am using the same function in another application that I am maintaining it returns me all the 1000 records. although setMaxResult has 50 as the parameter. Could you please tell me if maxResult() could be getting overridden by some configuration in the hibernate-properties or some other file.


    In case you need any other information please let me know.
    Thanks

  2. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    What database are you using - if there is no proper dialect or no support inside the jdbc driver you are out of luck. The best way to handle such a case is to use a Hibernate callback and manually set the MaxResults on the session - this works even if your hibernateTemplate is shared across various classes - setting properties over the template after it has been configured is not recommended as it might be already in use.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  3. #3
    Join Date
    Nov 2005
    Location
    India
    Posts
    16

    Lightbulb we can configure at xml file

    try to find out the configuration file setting the setMaxResult() attribute value in the config file, i think we can configure MaxResults thru configuration file with respect to a particular dataSource / Connection, all the best Buddy

Posting Permissions

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