borinquenkid opened a new pull request, #16582:
URL: https://github.com/apache/grails-core/pull/16582

   ## Problem
   
   On a database whose dialect generates native ids from a sequence 
(PostgreSQL, Oracle), `dbCreate: create-drop` with the default id mapping 
creates the tables but no sequences, and every save fails with `Identifier 
generator (SequenceStyleGenerator) was not properly initialized`. H2, MySQL and 
MariaDB use IDENTITY, which hid it.
   
   `GrailsNativeGenerator` called only `NativeGenerator.initialize(annotation, 
member, context)`, which picks the delegate for the dialect. Hibernate then 
runs `configure(...)`, `registerExportables(...)` and 
`initialize(SqlStringGenerationContext)` on a `NativeGenerator`. Grails builds 
the generator itself, outside Hibernate's generator binding, so none of those 
ran: the `SequenceStyleGenerator` delegate was never configured and never 
registered its sequence with the schema export. The constructor also swallowed 
every exception, so nothing reported it until the first save.
   
   ## Fix
   
   - `GrailsNativeGenerator` now takes the `JdbcEnvironment` and runs the four 
steps in Hibernate's order (the default `@NativeGenerator` annotation that 
`configure` reads comes from a private holder class). 
`GrailsSequenceGeneratorEnum` passes it through, as it already does for the 
sequence and table generators.
   - Fail fast: the constructor no longer swallows exceptions. A native 
generator that cannot be set up now stops the application at startup instead of 
failing on the first save. The reflective "was not properly initialized" guard 
in `generate()` only existed to report that late failure, so it is removed. The 
`ClassCastException` workaround for IDENTITY and the support for assigned 
identifiers are unchanged.
   - `GrailsNativeGeneratorSpec` builds a real context from an H2 datastore 
instead of relying on the swallowed exception, and the test of the removed 
guard is gone. In `GrailsSequenceGeneratorEnumSpec` the mocked table was built 
with `new Table("...")`, whose argument is the contributor, not the name; it 
now sets the name, because the native generator reads it.
   
   ## Tests
   
   `NativeIdGeneratorHibernate7Spec` boots a datastore with `dbCreate: 
create-drop` and the default id mapping (it does not extend 
`HibernateGormDatastoreSpec`, whose TCK manager sets `id generator: 'identity'` 
as the default mapping), saves two entities, reads them back, asserts distinct 
ids, and for a sequence-based dialect asserts the sequence exists in the 
database. It runs on the databases `RLikeHibernate7Spec` runs on: H2, 
PostgreSQL 16, MySQL 8, MariaDB 10.11 and Oracle Free (Testcontainers, skipped 
when no Docker socket is found).
   
   Red before the fix: PostgreSQL and Oracle fail with 
`HibernateSystemException: Identifier generator (SequenceStyleGenerator) was 
not properly initialized`; H2, MySQL and MariaDB pass. Green after the fix on 
all five. The full `:grails-data-hibernate7-core:test` passes (3710 tests, 22 
skipped); checkstyle and codenarc are clean.
   
   Fixes #16561
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to