Java Persistence API (JPA) Extensions Reference for EclipseLink, Release 2.5
  Go To Table Of Contents
 Search
 PDFComments
Comments


jdbc.fetch-size

Use eclipselink.jdbc.fetch-size to specify the number of rows to be fetched from the database when additional rows are needed.


NoteNote:

This property requires JDBC driver support.



Values

Table 4-15 describes this query hint's valid values.

Table 4-15 Valid Values for eclipselink.jdbc.fetch-size

Value Description

from 0 to Integer.MAX_VALUE

(Default = 0) As a String, depending on your JDBC driver.

If 0, the JDBC driver default will be used.



Usage

For queries that return a large number of objects, you can configure the row fetch size used in the query to improve performance by reducing the number database hits required to satisfy the selection criteria.

By default, most JDBC drivers use a fetch size of 10. , so if you are reading 1000 objects, increasing the fetch size to 256 can significantly reduce the time required to fetch the query's results. The optimal fetch size is not always obvious. Usually, a fetch size of one half or one quarter of the total expected result size is optimal.

If you are unsure of the result set size, incorrectly setting a fetch size too large or too small can decrease performance.


Examples

Example 4-32 shows how to use this hint in a JPA query.

Example 4-32 Using jdbc.fetch-size in a JPA Query

import org.eclipse.persistence.config.HintValues;
 import org.eclipse.persistence.config.QueryHints;
 query.setHint("eclipselink.JDBC_FETCH_SIZE", "100");

Example 4-33 shows how to use this hint with the @QueryHint annotation.

Example 4-33 Using jdbc.fetch-size in a @QueryHint Annotation

import org.eclipse.persistence.config.HintValues;
 import org.eclipse.persistence.config.QueryHints;
 @QueryHint(name=QueryHints.JDBC_FETCH_SIZE, value="100");


See Also

For more information, see: