我已经阅读了一些博客文章(例如: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()方法都在整个框架中使用。
那么有什么理由可以配置这个设置吗?
答案 0 :(得分: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 )