Skip to content

Hibernate 7: the default native id generator never creates its sequences on PostgreSQL #16561

Closed

Description

@sbglasius

Expected Behavior

With grails-data-hibernate7 8.0.0, PostgreSQL and dbCreate: create-drop, domain classes with the default id
mapping get their sequences created and can be saved, as with Hibernate 5.

Actual Behaviour

No create sequence statement is executed, and every save fails with:

org.hibernate.HibernateException: Identifier generator (SequenceStyleGenerator) was not properly initialized.
This usually happens if table creation failed (check previous logs for DDL errors).

There are no DDL errors. The tables are created; only the sequences are missing.

GrailsNativeGenerator's constructor calls initialize(null, null, context) and ignores any exception it throws.
On PostgreSQL the NativeGenerator delegate is a SequenceStyleGenerator that is never configured, so its sequence is
never registered as an exportable. On H2 the native generator uses IDENTITY, which is probably why the tests don't
catch it.

Mapping ids with id generator: 'sequence' works, because GrailsSequenceStyleGenerator configures the generator
and registers its exportables itself.

Steps To Reproduce

  1. A Grails 8.0.0 app with grails-data-hibernate7, a PostgreSQL datasource and dbCreate: create-drop
  2. Any domain class with the default id mapping
  3. new Book(title: 'x').save(flush: true)

Environment Information

  • Grails / GORM 8.0.0, grails-data-hibernate7, Hibernate 7.4.10.Final
  • PostgreSQL 17, Java 21

Example Application

gpc/grails-postgresql-extensions#136 (test-apps/app2 works around it in application.groovy)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions