PDA

View Full Version : problem in setMaxResult



ashish.abrol
Jul 14th, 2006, 04:25 AM
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


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

Costin Leau
Jul 14th, 2006, 05:37 AM
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.

sun7779
Jul 14th, 2006, 05:59 AM
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