Skip to content
Ameen Abozaid
Planned lessonJNR-028-L02

Identifiers and generation strategies

  • Lesson 2 of 8
  • Junior
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.
  • UUID ids can be created in Java before saving.
  • The id is null until the entity is saved (for generated ids).
  • Pick one strategy per project and keep it consistent with the schema.
Draft outline details

Demonstration

java
@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.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.