Mass data insertion via JpaRepository in Spring Boot and Kotlin
Hi everyone! I'm writing an application in Kotlin + Spring Boot + Hibernate, and I need to insert many records into a CockroachDB table. Currently, I'm doing this in a loop using saveAll():\n\n```kotlin\n@Repository\ninterface UserRepository : JpaRepository\n\n@Service\nclass UserService(private val repo: UserRepository) {\n fun insertUsers(users: List) {\n users.forEach { repo.save(it) } // or repo.saveAll(users)\n }\n}\n```\n\nProblem: if there are 1000+ users, this works very slowly. In the logs, I can see that Hibernate creates a separate INSERT for each record. I've read that batch inserts are possible, but I don't understand how to configure it properly.\n\nQuestions:\n1. How to do mass insertion via JpaRepository so that Hibernate combines INSERTs into one batch?\n2. Do I need to change ap
No answers yet.
Log in to leave an answer
Blogs
Working with Task Queues in Swift: A Complete Guide for Beginners
Top 10 JavaScript Frameworks for Web Development: From A to Z
Working with Databases in Go: PostgreSQL and MongoDB in Practice
Search in Rust: Finding the Index of an Array Element with Maximum Performance