I use spring batch JpaItemWriter to insert db with 11500 records(8 columns for that table), and I thought its performance will be good, but it was not as fast as I expected. 11500 records took about 60 seconds with chunk size 100, then I raise the size to 10000, but it still took about 50 seconds. Could any one suggest better way to do bulk insert or update by spring batch?
a better way to insert or update large amount of data by spring batch
The
JpaItemWriterdelegates item writing to a JPAEntityManager. So the performance of the writer is bound to the performance of the JPA implementation you use. What Spring Batch does is chunking items and then calling eitherentityManager.persistorentityManager.merge(depending on theusePersistparameter).That said, raw JDBC inserts usually perform better than JPA, but this depends on the case. You need to try both approaches and compare the results.