borinquenkid commented on code in PR #16582:
URL: https://github.com/apache/grails-core/pull/16582#discussion_r4290239269


##########
grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/generator/GrailsNativeGenerator.java:
##########
@@ -19,39 +19,59 @@
 package org.grails.orm.hibernate.cfg.domainbinding.generator;
 
 import java.io.Serial;
-import java.lang.reflect.Field;
+import java.util.Properties;
 
 import jakarta.persistence.GenerationType;
 
-import org.hibernate.HibernateException;
+import org.hibernate.boot.model.relational.Database;
+import org.hibernate.boot.model.relational.SqlStringGenerationContext;
+import 
org.hibernate.boot.model.relational.internal.SqlStringGenerationContextImpl;
+import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
 import org.hibernate.engine.spi.SharedSessionContractImplementor;
 import org.hibernate.generator.EventType;
 import org.hibernate.generator.GeneratorCreationContext;
 import org.hibernate.id.NativeGenerator;
-import org.hibernate.id.enhanced.SequenceStyleGenerator;
 
 /**
  * A native generator that supports Grails assigned identifiers and fixes 
Hibernate 7 ClassCastException.
  *
+ * <p>Hibernate drives {@link NativeGenerator} through {@code initialize} 
(which picks the delegate for the
+ * dialect), {@code configure} (which configures a sequence or table 
delegate), {@code registerExportables} (which
+ * adds the delegate's sequence or table to the schema export) and {@code 
initialize(SqlStringGenerationContext)}.
+ * Grails creates this generator itself instead of through Hibernate's 
generator binding, so it has to run every one
+ * of those steps. Skipping the middle ones leaves the delegate of a sequence 
based dialect without its sequence.

Review Comment:
   Added in 8400b27b03, folded into ยง71 of `upgrading80x.adoc` (retitled to 
cover both the explicit `id generator: 'sequence'` and the default mapping).
   
   It states that on a sequence-based dialect the default mapping now gets one 
`<table>_SEQ` per domain class where Grails 7 used the single 
`hibernate_sequence`, what each `dbCreate` mode does against an existing schema 
(`validate` fails with the missing-sequence message, `none` fails on the first 
save, `update` creates the sequence at 1 and collides with existing ids), and 
the two ways to upgrade: `hibernate.id.db_structure_naming_strategy: legacy`, 
or adding the new sequences above each table's highest id. I took the `legacy` 
behavior and the failure modes from your comment and did not rerun them.
   
   I also reran `NativeIdGeneratorHibernate7Spec` locally with Docker on this 
branch: green on H2, PostgreSQL, MySQL, MariaDB and Oracle.
   
   I left the `getSqlStringGenerationContext()` change for a follow-up covering 
all three generators, as you suggested.



-- 
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