Java – hibernate restricted result query
•
Java
How does the maxresult property of a hibernate query work? In the following example:
Query query = session.createQuery("from MyTable"); query.setMaxResults(10);
Does this get all rows from the database, but only show 10 of them? Or this is the same as the restriction in SQL
Solution
It is the same as limit, but it has nothing to do with the database For example, MS SQL server does not have a limit, so hibernate will be responsible for translating it For MySQL, it appends limit 10 to the query
Therefore, always use query setMaxResults(..) And query setFirstResult(..) Instead of native SQL clauses
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码