Identifiers and generation strategies
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
choose how ids are created.
Planned topics
IDENTITY: the database fills the id on insert (PostgreSQL identity column); simple, but Hibernate must insert immediately, which disables insert batching.SEQUENCE: Hibernate asks a sequence for ids, can fetch many at once, and supports batching; usually better for PostgreSQL.UUIDids can be created in Java before saving.- The id is
nulluntil the entity is saved (for generated ids). - Pick one strategy per project and keep it consistent with the schema.
Draft outline details
Demonstration
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "product_seq")
@SequenceGenerator(name = "product_seq", sequenceName = "product_seq", allocationSize = 50)
private Long id;Check your understanding
Which strategy disables insert batching?
Show answer
IDENTITY.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.