Search code examples
spring-bootspring-data

spring data saveAll very slow


i m using spring data saveAll to save 3500 records in an Oracle database but it execute very slowly, is there a way to do bulk insert or any other fast way

 noteRepository.saveAll(noteEntityList);//<- this one is slow for 3000 records

thanks in advance


Solution

  • By default, saveAll does not create batch, the batch processing needs to be enabled. You need to set below properties to enable batch processing

    spring.jpa.properties.hibernate.jdbc.batch_size=100
    spring.jpa.properties.hibernate.order_inserts=true (if inserts)
    OR
    spring.jpa.properties.hibernate.order_updates=true (if updates)
    

    First property collects the transaction in batch and second property collects the statements grouped by entity.

    Check this thread for more details How to do bulk (multi row) inserts with JpaRepository?