I am using the following code to execute an HQL query with Hibernate:
String myHqlQuery = "select from MyTable where Something = ? order by SomeVal";
// Set bind values ...
getHibernateTemplate().find(myHqlQuery, bindParams);
Now, I want to select the top N rows from the table. I know mySql has the LIMIT keyword which is not available in HQL. I also know that Hibernate has the setMaxResults()
method you can run on a Query
object.
My question is - is there any way to add the "limit" constraint without have to change my code too much (i.e. executing the query via a HibernateTemplate object)?