hibernate.jdbc.fetch_size的默认大小是多少? [英] what's the default size of hibernate.jdbc.fetch_size?
问题描述
我们知道默认情况下,大多数jdbc驱动程序的抓取大小是10。
有没有人知道hibernate中的默认抓取大小,即hibernate.jdbc.fetch_size是 $ c> instance。这是通过 ohcSettingsFactory#buildSettings()
方法完成的,它包含以下行:
code> Integer statementFetchSize = PropertiesHelper.getInteger(Environment.STATEMENT_FETCH_SIZE,properties);
if(statementFetchSize!= null)log.info(JDBC result set fetch size:+ statementFetchSize);
settings.setJdbcFetchSize(statementFetchSize);
因此,允许使用 null
此设置随后用于 ohjAbstractBatcher.java#setStatementFetchSize
private void setStatementFetchSize(PreparedStatement语句)throws SQLException {
Integer statementFetchSize = factory.getSettings ().getJdbcFetchSize();
if(statementFetchSize!= null){
statement.setFetchSize(statementFetchSize.intValue());
}
}
这个私有方法在准备 PreparedStatement
或 CallableStatement
。请参阅 AbstractBatcher
中的 prepareQueryStatement
和 prepareCallableQueryStatement
。
所以,默认值是 null
,并导致Hibernate不调用语句#setFetchSize code>。
这实际上归纳在参考文档中:
< h3> 3.4。可选配置属性
...
hibernate.jdbc.fetch_size
:非零值决定JDBC提取大小(调用
Statement.setFetchSize()
)
< blockquote>
这里是javadoc必须说的
语句#setFetchSize()
:
为JDBC驱动程序提供一个 hint 关于
应从数据库获取的行数行是
需要的ResultSet对象genrated
通过此语句。如果指定的值
为零,则提示为
被忽略。 默认值为零
换句话说,当使用
null
fetch_size
,JDBC驱动程序将使用零的默认值。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 theo.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 aCallableStatement
. SeeprepareQueryStatement
andprepareCallableQueryStatement
inAbstractBatcher
.So, the default value is
null
and results in Hibernate not callingStatement#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 (callsStatement.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.这篇关于hibernate.jdbc.fetch_size的默认大小是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!