Hi,All:)
I have set "hibernate.jdbc.fetch_size" to 32.
when I execute a simple query, which result contains only 1 row,
the thread seems hang up for a long time;
I execute the same query with a different parameter, which result contains 75 rows, the execution is very fast.
I traced Hibernate's code in both situations, and noticed Hibernate called the following method each time:
Code:
AbstractBatcher.java Line:540:
private void setStatementFetchSize(PreparedStatement statement) throws SQLException {
Integer statementFetchSize = factory.getSettings().getJdbcFetchSize();
if ( statementFetchSize!=null ) {
statement.setFetchSize( statementFetchSize.intValue() );
}
}
Here is the explanation about setFetchSize in java.sql.Statement:
Code:
/**
* Gives the JDBC driver a hint as to the number of rows that should
* be fetched from the database when more rows are needed. The number
* of rows specified affects only result sets created using this
* statement. If the value specified is zero, then the hint is ignored.
* The default value is zero.
*
* @param rows the number of rows to fetch
* @exception SQLException if a database access error occurs, or the
* condition 0 <= <code>rows</code> <= <code>this.getMaxRows()</code>
* is not satisfied.
* @since 1.2
* @see #getFetchSize
*/
But in my first case, I didn't get a SQLException and finally got the result.
I think it looks like my jdbc's problem, but I still have a question, should Hibernate call setFetchSize every time, even when the result size is smaller than the configration value "hibernate.jdbc.fetch_size"?
My Hibernate version is 3.2.1.ga, and my JDBC version is sybase jConnect for JDBC 3.0 Build (25308)
My Hibernate Configuration Properties are as follows:
Code:
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SybaseDialect
</prop>
<prop key="hibernate.connection.charSet">cp936</prop>
<prop key="hibernate.connection.autocommit">true</prop>
<prop key="hibernate.jdbc.batch_size">32</prop>
<prop key="hibernate.max_fetch_depth">3</prop>
<prop key="hibernate.jdbc.fetch_size">32</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.provider_class">
org.hibernate.cache.EhCacheProvider
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.generate_statistics">true</prop>
</props>
</property>
Thanks very much!