Best way to save the large number of records in hibernate

后端 未结 2 870
旧巷少年郎
旧巷少年郎 2021-01-23 09:11

I have 5000 records to be saved. what is the best way in the database point of view, whether to save individual records(save(record) 5000 times) or saveAll(list of 5000 records)

2条回答
  •  佛祖请我去吃肉
    2021-01-23 09:21

    Use the feature batch Insertion in Hibernate.

    Batch Insertion is a powerful feature of hibernate particularly useful when you are importing data from other systems in batch. If you do not use batch feature of hibernate, your application's performance may decrease dramatically at the time of insertion of many records.

    Here is a simple comparison on normal save and Batch insert.

    And also official docs.

提交回复
热议问题