Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between setMaxResults and setFetchSize in org.hibernate.Query?

Tags:

java

hibernate

What is difference between setMaxResults and setFetchSize in org.hibernate.Query? I just can no get it =)

like image 859
user590444 Avatar asked May 22 '11 11:05

user590444


People also ask

What is setMaxResults?

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.

What is org hibernate fetchSize?

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.


1 Answers

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.

like image 106
dev4life Avatar answered Oct 21 '22 00:10

dev4life