Hibernate: GenerationType.IDENTITY disables JDBC batching

Hibernate must execute each insert to learn the generated id, so it cannot batch them.

Code
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)   // no batching
Long id;

@Id @GeneratedValue(strategy = GenerationType.SEQUENCE,
                    generator = "order_seq")
@SequenceGenerator(name = "order_seq", allocationSize = 50)  // batches fine
Long id;
Output
IDENTITY: 1000 inserts = 1000 round trips.
SEQUENCE with allocationSize 50: 20 sequence calls + batched inserts.
Advertisement

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-08-11