-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Problem with "hibernate.jdbc.fetch_size"
PostPosted: Wed Dec 26, 2007 8:37 am 
Newbie

Joined: Wed Dec 26, 2007 7:34 am
Posts: 2
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!


Top
 Profile  
 
 Post subject: There was a misunderstanding in my previous post
PostPosted: Fri Dec 28, 2007 4:04 am 
Newbie

Joined: Wed Dec 26, 2007 7:34 am
Posts: 2
In my previous post I mentioned:
Quote:
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"?

I misunderstood the "result size" and the value returned by getMaxRows(),

actually, the java.sql.Statement specified that a SQLException should throw if we call Statement.setFetchSize(size) with size > Statement.getMaxRows(), not size > the actual result size.

I wrote a simple code to test my sybase jdbc, when I called Statement.setMaxRows() before Statement.setFetchSize() as following:
Code:
stmt.setMaxRows(7);
stmt.setFetchSize(8);

the SQLException threw as expected.

if I wrote like this:
Code:
stmt.setFetchSize(8);
stmt.setMaxRows(7);

There was no SQLException and the thread hang up for about 10mins,and finally return the result.

I tested the two approaches with oracle jdbc, both cases worked fine,but there was no SQLException threw when FetchSize > MaxRows.

So far, we can see it's quite different between vendor's implementations, and when I traced my application in Hibernate enviroment, I noticed that Hibernate called setFetchSize before setMaxRows(the code snippet locates in method prepareQueryStatement in org.hibernate.loader.Loader).

So I doubt that if there is any necessary to call setMaxRows before setFetchSize in Hibernate?

Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.