mike mike - 2 months ago 16
Java Question

What causes Hibernate Session#update to be slow?

I have the following:

public void batchSave(Iterable<T> entities) {
int i = 0;

for (T entity : entities) {

if (i % BATCH_SIZE == 0) {


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.

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.

My understanding is that
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.


This turned out to be an oversight in that the latter table was not correctly indexed, so the updates were taking longer at the DB.