liveBook · Manning

Pre-insert identifier generator

As explained in Java Persistence with Spring Data and Hibernate epub

A pre-insert identifier generator assigns an entity identifier before the entity's SQL INSERT is executed.

A pre-insert identifier generator assigns an entity identifier independently before its SQL INSERT executes. This lets an ORM queue inserts for later execution while still making the identifier available when generation can occur during persist. section 5.2.5

Prefer this strategy when:

  • Insert batching matters, because ORM services can delay SQL execution until later in the unit of work. section 5.2.5
  • Application code may read the identifier after persist; post-insert mechanisms can leave it null until INSERT completes. section 5.2.5
  • Portability matters: enhanced-sequence uses a native database sequence where supported and emulates one with a single-row table otherwise. section 5.2.5

Sequence-backed generation

An enhanced-sequence generator obtains identifiers from a shared, concurrently accessible database sequence before INSERT. Auto-incremented columns, column defaults, and trigger-generated keys instead become available only after INSERT. section 5.2.5

How Java Persistence with Spring Data and Hibernate epub covers it

How deep it goes
Explains deferred INSERT execution and contrasts independent pre-insert generation with database-generated post-insert keys.
Examples
Uses enhanced-sequence, native database sequences, and a single-row table sequence emulator as concrete strategies.
What it assumes
Assumes familiarity with entities, ORM persistence, SQL INSERT statements, and database-generated identifiers.
What you can do after
Choose identifier generation that preserves early identifier availability, batching, portability, or database-specific behavior.
How it connects
Connects ORM persistence with JDBC batching, database sequences, auto-increment columns, defaults, triggers, JPA, and Hibernate.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Java Persistence with Spring Data and Hibernate epub. The section links point to the parts of the book it draws on.