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?
解决方案
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.