Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's the default size of hibernate.jdbc.fetch_size?

We know by default, most of jdbc drivers' fetch sizes are 10.

does anyone know what the default fetch size in hibernate, namely hibernate.jdbc.fetch_size is?

like image 606
ligerdave Avatar asked Jul 28 '10 16:07

ligerdave


People also ask

What is Hibernate JDBC Fetch_size?

In the first case, hibernate. jdbc. fetch_size sets the statement's fetch size within the JDBC driver, that is the number of rows fetched when there is more than a one row result on select statements.

What is the default fetch size in JDBC?

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.

How does JDBC fetch size work?

Fetch Size. By default, when Oracle JDBC runs a query, it retrieves a result set of 10 rows at a time from the database cursor. This is the default Oracle row fetch size value. You can change the number of rows retrieved with each trip to the database cursor by changing the row fetch size value.

What is fetch size?

The fetch size is the default value for statement and prepared statement to a returns database record of the 10 sizes. The fetch size is a property that uses a statement to fetch more than one database row using a driver. The fetch size is method gives hints to the driver to maintain or manage database rows.


1 Answers

Basically, all the configuration settings are used to build a o.h.c.Settings instance. This is done by the o.h.c.SettingsFactory#buildSettings() method which contains the following lines:

Integer statementFetchSize = PropertiesHelper.getInteger(Environment.STATEMENT_FETCH_SIZE, properties);
if (statementFetchSize!=null) log.info("JDBC result set fetch size: " + statementFetchSize);
settings.setJdbcFetchSize(statementFetchSize);

So, a null value is allowed, it won't be translated and will be "propagated" as such.

This setting is then used in o.h.j.AbstractBatcher.java#setStatementFetchSize:

private void setStatementFetchSize(PreparedStatement statement) throws SQLException {
    Integer statementFetchSize = factory.getSettings().getJdbcFetchSize();
    if ( statementFetchSize!=null ) {
        statement.setFetchSize( statementFetchSize.intValue() );
    }
}

This private method is called when preparing a PreparedStatement or a CallableStatement. See prepareQueryStatement and prepareCallableQueryStatement in AbstractBatcher.

So, the default value is null and results in Hibernate not calling Statement#setFetchSize().

This is actually summarized in the Reference Documentation:

3.4. Optional configuration properties

...

hibernate.jdbc.fetch_size: A non-zero value determines the JDBC fetch size (calls Statement.setFetchSize())

And here is what the javadoc has to say about Statement#setFetchSize():

Gives the JDBC driver a hint as to the number of rows that should be fetched from the database when more rows are needed for ResultSet objects genrated by this Statement. If the value specified is zero, then the hint is ignored. The default value is zero.

In other words, when using a null fetch_size, the JDBC driver will use the default value which is zero.

like image 173
Pascal Thivent Avatar answered Dec 16 '22 08:12

Pascal Thivent