0

我读过一些博客文章(例如: http: //orapath.blogspot.com.br/2012/04/hibernate.html,http : //abramsm.wordpress.com/2008/04/23/hibernate-batch- processing-why-you-may-not-be-using-it-even-if-you-think-you-are/)建议将 hibernate.jdbc.batch_size 配置属性设置为更高的值,以获得更好的处理性能批量插入/更新。

但是,浏览 Hibernate 4.1.8 源代码我可以看到,org.hibernate.cfg.Settings 中的字段 jdbcBatchSize 和反映此属性设置的相应 getter getJdbcBatchSize() 方法都没有在整个框架中使用。

那么有什么理由来配置这个设置吗?

4

1 回答 1

1

字段 Settings.jdbcBatchSize 好像没有用到,实际配置用在其他地方。我下载了 hibernate-core 的源代码,通过文本搜索可以找到 Environment.STATEMENT_BATCH_SIZE 在某些地方使用。

看看 org.hibernate.engine.jdbc.batch.internal.BatchBuilderImpl.java

文本搜索的结果

Search "STATEMENT_BATCH_SIZE" (23 hits in 22 files)
  C:\Documents and Settings\cfweber\Desktop\hibernate\core\org\hibernate\cfg\AvailableSettings.java (1 hit)
    Line 190:   public static final String STATEMENT_BATCH_SIZE = "hibernate.jdbc.batch_size";
  C:\Documents and Settings\cfweber\Desktop\hibernate\core\org\hibernate\cfg\ExternalSessionFactoryConfig.java (1 hit)
    Line 281:       setUnlessNull( props, Environment.STATEMENT_BATCH_SIZE, jdbcBatchSize );
  C:\Documents and Settings\cfweber\Desktop\hibernate\core\org\hibernate\cfg\SettingsFactory.java (1 hit)
    Line 114:       int batchSize = ConfigurationHelper.getInt(Environment.STATEMENT_BATCH_SIZE, properties, 0);
  C:\Documents and Settings\cfweber\Desktop\hibernate\core\org\hibernate\dialect\AbstractTransactSQLDialect.java (1 hit)
    Line 125:       getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, NO_BATCH);
  C:\Documents and Settings\cfweber\Desktop\hibernate\core\org\hibernate\dialect\Cache71Dialect.java (2 hits)
    Line 258:       getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
    Line 259:       //getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, NO_BATCH);
  C:\Documents and Settings\cfweber\Desktop\hibernate\core\org\hibernate\dialect\CUBRIDDialect.java (1 hit)
    Line 76:         getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
  C:\Documents and Settings\cfweber\Desktop\hibernate\core\org\hibernate\dialect\DB2Dialect.java (1 hit)
    Line 177:       getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, NO_BATCH );
  C:\Documents and Settings\cfweber\Desktop\hibernate\core\org\hibernate\dialect\H2Dialect.java (1 hit)
    Line 191:       getDefaultProperties().setProperty( AvailableSettings.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
  C:\Documents and Settings\cfweber\Desktop\hibernate\core\org\hibernate\dialect\HSQLDialect.java (1 hit)
    Line 219:       getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
  C:\Documents and Settings\cfweber\Desktop\hibernate\core\org\hibernate\dialect\InterbaseDialect.java (1 hit)
    Line 59:        getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, NO_BATCH);
  C:\Documents and Settings\cfweber\Desktop\hibernate\core\org\hibernate\dialect\JDataStoreDialect.java (1 hit)
    Line 60:        getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
  C:\Documents and Settings\cfweber\Desktop\hibernate\core\org\hibernate\dialect\MckoiDialect.java (1 hit)
    Line 81:        getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, NO_BATCH);
  C:\Documents and Settings\cfweber\Desktop\hibernate\core\org\hibernate\dialect\MimerSQLDialect.java (1 hit)
    Line 136:       getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, "50");
  C:\Documents and Settings\cfweber\Desktop\hibernate\core\org\hibernate\dialect\MySQLDialect.java (1 hit)
    Line 182:       getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE);
  C:\Documents and Settings\cfweber\Desktop\hibernate\core\org\hibernate\dialect\Oracle8iDialect.java (1 hit)
    Line 200:       getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE );
  C:\Documents and Settings\cfweber\Desktop\hibernate\core\org\hibernate\dialect\Oracle9Dialect.java (1 hit)
    Line 87:        getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE);
  C:\Documents and Settings\cfweber\Desktop\hibernate\core\org\hibernate\dialect\PostgreSQL81Dialect.java (1 hit)
    Line 154:       getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE);
  C:\Documents and Settings\cfweber\Desktop\hibernate\core\org\hibernate\dialect\SAPDBDialect.java (1 hit)
    Line 136:       getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE);
  C:\Documents and Settings\cfweber\Desktop\hibernate\core\org\hibernate\dialect\TeradataDialect.java (1 hit)
    Line 110:       getDefaultProperties().setProperty( Environment.STATEMENT_BATCH_SIZE, NO_BATCH );
  C:\Documents and Settings\cfweber\Desktop\hibernate\core\org\hibernate\dialect\TimesTenDialect.java (1 hit)
    Line 84:        getDefaultProperties().setProperty(Environment.STATEMENT_BATCH_SIZE, DEFAULT_BATCH_SIZE);
  C:\Documents and Settings\cfweber\Desktop\hibernate\core\org\hibernate\engine\jdbc\batch\internal\BatchBuilderImpl.java (1 hit)
    Line 55:        size = ConfigurationHelper.getInt( Environment.STATEMENT_BATCH_SIZE, configurationValues, size );
  C:\Documents and Settings\cfweber\Desktop\hibernate\core\org\hibernate\engine\jdbc\batch\internal\BatchBuilderInitiator.java (1 hit)
    Line 55:                    ConfigurationHelper.getInt( Environment.STATEMENT_BATCH_SIZE, configurationValues, 1 )
于 2013-01-07T17:13:18.457 回答