0

currently I am using the following to pull rows from a table called Table:

return getHibernateTemplate().find("from Table");

How do I use hibernate to pull only the first n rows from the table (i.e. like a mySql limit would do)?

Thanks.

Update: so is this the proper way to do it?

getHibernateTemplate().setMaxResults(35);
return getHibernateTemplate().find("from Table");
2
  • 1
    It would be better to use a hibernate Query object to do the load and then set the max results on that. Problem with doing what you suggest is that it will be set on the hibernate template and that object is re-used. So the limit will be set for other queries as well. Commented Feb 5, 2010 at 6:35
  • I looked into this, what about using Criteria to acheive this? What would be the benefits / downsides to using Criteria over Query object? Thanks Commented Feb 5, 2010 at 19:34

2 Answers 2

2

Use HIbernateTemplate setMaxResults to limit the results.

Sign up to request clarification or add additional context in comments.

1 Comment

Is the code that I updated in my question the proper way to do it?
0

I ended up using a Hibernate Criteria query to do this and it works properly. I made use of the setFirstResult() and setLastResults() methods.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.