How to commit batches of inserts in hibernate?
问题 I have to save a large number of objects to the database using hibernate. Instead of commiting all of them at once, I would like to commit as soon as n (BATCH_SIZE) objects are present in the session. Session session = getSession(); session.setCacheMode(CacheMode.IGNORE); for(int i=0;i<objects.length;i++){ session.save(objects[i]); if( (i+1) % BATCH_SIZE == 0){ session.flush(); session.clear(); } } I would have tried something like above, but I read that session.flush() does not commit the