Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jpa spring boot - hibernate insert slow

I have three lists of entities that i'm trying to save to the database.

in total it's about 1000 entites it have to persist.

entityRepo.save(EntityList);

However this takes 4-5 minutes to complete. - And i noticed its doing some selects before the inserts, I assume it's hibernate dirty checking to see if it needs to update or insert.

Anyway to disable this and improve the speed of hibernate insert ?

been looking into flushing but not sure how to do it when saving an entire list at once ?

like image 787
Anders Pedersen Avatar asked Mar 21 '26 16:03

Anders Pedersen


1 Answers

If all the entities are the same then you should turn on batch-inserts. Here's a couple of articles to get you started. It's primarily just adding some configuration.

http://memorynotfound.com/hibernate-jpa-batch-insert-batch-update-example/ https://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/chapters/batch/Batching.html

like image 184
Gregg Avatar answered Mar 24 '26 06:03

Gregg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!