What is difference between setMaxResults
and setFetchSize
in org.hibernate.Query? I just can no get it =)
Query setMaxResults(int maxResult) Set the maximum number of results to retrieve. Parameters: maxResult - maximum number of results to retrieve Returns: the same query instance Throws: IllegalArgumentException - if the argument is negative.
org. hibernate. fetchSize (Long – number of records) Hibernate provides the value of this hint to the JDBC driver to define the number of rows the driver shall receive in one batch. This can improve the communication between the JDBC driver and the database, if it's supported by the driver.
setMaxResults
is the same as LIMIT
in SQL- you are setting the maximum number of rows you want returned. This is a very common use case of course.
setFetchSize
is about optimization, which can change how Hibernate goes about sending the results to the caller (example: buffered, in different size chunks). setFetchSize
is NOT implemented by all database drivers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With