title: What causes Hibernate Session#update to be slow?
body: <p>I have the following:</p>
  
  <pre><code>public void batchSave(Iterable&lt;T&gt; entities) {
      int i = 0;
  
      for (T entity : entities) {
          session.update(entity);
          i++;
  
          if (i % BATCH_SIZE == 0) {
              session.flush();
              session.clear();
          }
      }
  
      session.flush();
      session.clear();
  }
  </code></pre>
  
  <p>This method is invoked on 2 occasions, once with an input of size ~28000 and once with an input of size ~32000, so not much difference in terms of size.</p>
  
  <p>However, the latter takes much much longer to run. My question is what would cause this function to run longer once as opposed to the other time? Given all other properties are equal between the two, I would expect these to finish in similar time.</p>
  
  <p>My understanding is that <code>session.update(object)</code> issues an update to the DB, but I should note that in the group of 32000, almost all of the objects have had their state modified, whereas for the 28000 only about 5000 of them have. Even so, the 28000 size collection takes maybe 2s while the slightly larger one seems to run for minutes.</p>