How does maxresult property of hibernate query works? in the example below :
Query query = session.createQuery("from MyTable");
query.setMaxResults(10);
Does this get all rows from database, but only 10 of them are displayed? or this is same as limit in sql.
It’s the same as
LIMIT, but it is database-independent. For example MS SQL Server does not have LIMIT, so hibernate takes care of translating this. For MySQL it appendsLIMIT 10to the query.So, always use
query.setMaxResults(..)andquery.setFirstResult(..)instead of native sql clauses.