Skip to main content

Hibernate

Hibernate ID Generation: IDENTITY vs SEQUENCE vs UUID v7, and Why Batch Inserts Break

Hibernate 7.4.14 primary keys, measured: IDENTITY turns JDBC batching off silently (10,000 inserts became 10,000 single executes), a pooled SEQUENCE needed 400 round trips, and a sequence whose INCREMENT BY disagrees with allocationSize produced negative and duplicate ids. On UUIDs, the common premise is half wrong: Style.TIME is a version-1-flagged id with a constant IP/JVM half, while real RFC 9562 version 7 ships as Style.VERSION_7 from Hibernate 7.0.0. Includes order_inserts, AUTO across six dialects, an H2 index-size comparison (PostgreSQL could not be run), and the Spring Data SELECT-before-INSERT on assigned ids.

Soft Delete in Hibernate 7: @SoftDelete vs @SQLDelete + @SQLRestriction

Hibernate 7's native @SoftDelete (DELETED, ACTIVE and TIMESTAMP strategies) compared with the hand-rolled @SQLDelete + @SQLRestriction recipe, run against PostgreSQL 17 and H2: the generated SQL, restoring rows, the unique-index traps (partial indexes, NULLS NOT DISTINCT), associations and join tables, native queries that bypass the filter, and what Spring Data JPA does with it.