title: Hibernate batch with stored procedure
body: <p>I have a Stored Procedure designed to insert a single row. I operate on it with Hibernate in the following way (simplified example):</p>
  
  <pre><code>public void store(int param1, int param2) {
     Connection con = session.connection();  // obtain JDBC connection from Session object
     CallableStatement stmt = con.prepareCall("{ call changesalary(?,?) }");
     stmt.setInt(1, param1);  // first parameter index start with 1
     stmt.setInt(2, param2); // second parameter
     stmt.execute();  // call stored procedure
     cleanup(con, stmt);
  }
  </code></pre>
  
  <p>I wonder if it is possible to reuse this Store Procedure in a more Batch-alike way without having to modify it (I don't have the possibility of adding a new Stored Procedure or modify the existing). I want to do this:</p>
  
  <pre><code>public void batchStore(int[] params1, int[] params2) {
      for (int i = 0; i &lt; params1.length; i++) {
          store(params1[i], params2[i]);
      }
  }
  
  public void store(int param1, int param2) {
     Connection con = session.connection();
     CallableStatement stmt = con.prepareCall("{ call changesalary(?,?) }");
     stmt.setInt(1, param1);
     stmt.setInt(2, param2);
     stmt.execute();
     cleanup(con, stmt);
  }
  </code></pre>
  
  <p>But in order to avoid a large amount of calls to the DB, I would rather like to prepare a set of Statements, that I then batch to the database in one call:</p>
  
  <pre><code>public void store(int[] params1, int[] params2) {
     Connection con = session.connection();
     CallableStatement[] stmts = new CallableStatements[params.size];
  
     for (int i = 0; i &lt; params1.length; i++) {
         CallableStatement stmt = con.prepareCall("{ call changesalary(?,?) }");
         stmt.setInt(1, params1[i]);
         stmt.setInt(2, params2[i]);  
         stmts[i] = stmt;
      }
  
      con.executeStatements(stmts);
  }
  </code></pre>
  
  <p>Can the above pseudo code be achieved, and will I increase performance by doing so?</p>