One million rows, PostgreSQL, HikariCP pool of 10, SEQUENCE generator: approximately 12 seconds with proper Hibernate batch configuration. Without it, the same job runs for over two minutes — and that’s before accounting for the OutOfMemoryError you get around row 80,000 if you skip the flush/clear cycle.
The configuration is four properties. The JDBC trap is one silent gotcha that disables batching without any error. The flush/clear cadence is one loop pattern. This post covers all three and the approximate numbers so you can reason about what your specific job should take.
The Problem: The “Chatty” Database Trap
When you persist objects in a standard loop, Hibernate sends one INSERT or UPDATE statement per object. This creates massive network latency. Imagine you have 10,000 records and a 5ms network round-trip delay. You have already lost 50 seconds just to “talk” to the database, even before the engine starts processing the data.
This is often called the “N+1 Problem of Writing.” Each individual insert requires the database to parse the SQL, execute it, update indexes, and send an acknowledgment. Multiplying this overhead by thousands of records is the fastest way to kill application performance.
Continue reading Hibernate 7 Batch Insert: 1M Rows in 12s — Settings, Benchmarks, and the JDBC Trap