# 批量抓取和更新

1）
hibernate.max_fetch_depth

hibernate.default_batch_fetch_size

2）
hibernate.jdbc.fetch_size

hibernate.jdbc.batch_size

 /**     * 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     */

Statement.executeBatch()的说明：
**     * Submits a batch of commands to the database for execution and     * if all commands execute successfully, returns an array of update counts.     * The <code>int</code> elements of the array that is returned are ordered     * to correspond to the commands in the batch, which are ordered      * according to the order in which they were added to the batch.     * The elements in the array returned by the method <code>executeBatch</code>     * may be one of the following:     * <OL>     * <LI>A number greater than or equal to zero -- indicates that the     * command was processed successfully and is an update count giving the     * number of rows in the database that were affected by the command's     * execution     * <LI>A value of <code>SUCCESS_NO_INFO</code> -- indicates that the command was     * processed successfully but that the number of rows affected is     * unknown     * <P>      * If one of the commands in a batch update fails to execute properly,     * this method throws a <code>BatchUpdateException</code>, and a JDBC     * driver may or may not continue to process the remaining commands in     * the batch.  However, the driver's behavior must be consistent with a     * particular DBMS, either always continuing to process commands or never     * continuing to process commands.  If the driver continues processing     * after a failure, the array returned by the method     * <code>BatchUpdateException.getUpdateCounts</code>     * will contain as many elements as there are commands in the batch, and     * at least one of the elements will be the following:     * <P>      * <LI>A value of <code>EXECUTE_FAILED</code> -- indicates that the command failed     * to execute successfully and occurs only if a driver continues to     * process commands after a command fails     * </OL>     * <P>     * A driver is not required to implement this method.     * The possible implementations and return values have been modified in     * the Java 2 SDK, Standard Edition, version 1.3 to     * accommodate the option of continuing to proccess commands in a batch     * update after a <code>BatchUpdateException</code> obejct has been thrown.     *     * @return an array of update counts containing one element for each     * command in the batch.  The elements of the array are ordered according      * to the order in which commands were added to the batch.     * @exception SQLException if a database access error occurs or the     * driver does not support batch statements. Throws {@link BatchUpdateException}     * (a subclass of <code>SQLException</code>) if one of the commands sent to the     * database fails to execute properly or attempts to return a result set.     * @since 1.3     */

batch参考代码：
boolean isSupportBatchUpdates(Connection conn)   DatabaseMetaData dbm = con.getMetaData();   if(dbm.supportBatchUpdates())     return true;   //notice: catch SQLException,AbstractMethodError   return false;int[] batchUpdate(String[] sql)   //make sure sql is not null!!!   int res = new int[sql.length];   if(isSupportBatchUpdates(conn)){      for(int i = 0;i<sql.length;i++)        stmt.addBatch(sql[i]);      res = stmt.executeBatch();   } else {      for(int i = 0 ;i<sql.length;i++){         if(!stmt.execute(sql[i])) //非select，DML/DDL            res[i] = stmt.getUpdateCount();         else throw new ....      }   }   return res;