This is an automated email from the ASF dual-hosted git repository. borinquenkid pushed a commit to branch 8.0.x-hibernate7 in repository https://gitbox.apache.org/repos/asf/grails-core.git
commit e9eedb1f1add7e48e1a65cff596050309b1eecb4 Author: Walter B Duque de Estrada <[email protected]> AuthorDate: Sun Jan 18 22:27:46 2026 -0600 update progress --- .../cfg/domainbinding/BasicValueIdCreator.java | 22 +++++++---- .../domainbinding/GrailsIncrementGenerator.java | 17 +++++++++ .../cfg/domainbinding/GrailsTableGenerator.java | 43 ++++++++++++++++++++++ 3 files changed, 74 insertions(+), 8 deletions(-) diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/BasicValueIdCreator.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/BasicValueIdCreator.java index 9600936a0e..f7dbf96098 100644 --- a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/BasicValueIdCreator.java +++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/BasicValueIdCreator.java @@ -3,6 +3,7 @@ package org.grails.orm.hibernate.cfg.domainbinding; import java.util.HashMap; import java.util.Map; import java.util.Optional; +import java.util.Properties; import java.util.function.BiFunction; import org.hibernate.boot.spi.MetadataBuildingContext; @@ -45,20 +46,25 @@ public class BasicValueIdCreator { generatorFactories.put("uuid", (context, mappedId) -> new UuidGenerator(context.getType().getReturnedClass())); generatorFactories.put("uuid2", (context, mappedId) -> new UuidGenerator(context.getType().getReturnedClass())); generatorFactories.put("assigned", (context, mappedId) -> new Assigned()); - generatorFactories.put("table", (context, mappedId) -> new TableGenerator()); - generatorFactories.put("enhanced-table", (context, mappedId) -> new TableGenerator()); + generatorFactories.put("table", (context, mappedId) -> new GrailsTableGenerator(context, mappedId)); + generatorFactories.put("enhanced-table", (context, mappedId) -> new GrailsTableGenerator(context,mappedId)); generatorFactories.put("hilo", (context, mappedId) -> new SequenceStyleGenerator()); } public BasicValue getBasicValueId(RootClass entity, Identity mappedId, boolean useSequence) { BasicValue id = new BasicValue(metadataBuildingContext, entity.getTable()); - String generator = determineGeneratorName(mappedId, useSequence); + String generatorName = determineGeneratorName(mappedId, useSequence); + final String entityName = entity.getEntityName(); + + id.setCustomIdGeneratorCreator(context -> { + // Ensure the ID object knows which entity it belongs to + if (mappedId != null && mappedId.getName() == null) { + mappedId.setName(entityName); + } + return generatorFactories.getOrDefault(generatorName, (ctx, mid) -> new GrailsNativeGenerator(ctx)) + .apply(context, mappedId); + }); - id.setCustomIdGeneratorCreator(context -> - generatorFactories.getOrDefault(generator, (ctx, mid) -> new GrailsNativeGenerator(ctx)) - .apply(context, mappedId) - ); - return id; } diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/GrailsIncrementGenerator.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/GrailsIncrementGenerator.java new file mode 100644 index 0000000000..6f7fbe221d --- /dev/null +++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/GrailsIncrementGenerator.java @@ -0,0 +1,17 @@ +package org.grails.orm.hibernate.cfg.domainbinding; + +import org.hibernate.generator.GeneratorCreationContext; +import org.hibernate.id.IncrementGenerator; + +import java.util.Optional; +import java.util.Properties; + +import org.grails.orm.hibernate.cfg.Identity; + +public class GrailsIncrementGenerator extends IncrementGenerator { + + public GrailsIncrementGenerator(GeneratorCreationContext context, org.grails.orm.hibernate.cfg.Identity mappedId) { + var generatorProps = Optional.ofNullable(mappedId).map(Identity::getProperties).orElse(new Properties()); + super.configure(context, generatorProps); + } +} \ No newline at end of file diff --git a/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/GrailsTableGenerator.java b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/GrailsTableGenerator.java new file mode 100644 index 0000000000..336edfa39d --- /dev/null +++ b/grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/cfg/domainbinding/GrailsTableGenerator.java @@ -0,0 +1,43 @@ +package org.grails.orm.hibernate.cfg.domainbinding; + +import org.hibernate.generator.GeneratorCreationContext; +import org.hibernate.id.enhanced.TableGenerator; +import org.hibernate.id.enhanced.StandardOptimizerDescriptor; +import org.grails.orm.hibernate.cfg.Identity; + +import java.util.Optional; +import java.util.Properties; + +public class GrailsTableGenerator extends TableGenerator { + + public GrailsTableGenerator(GeneratorCreationContext context, Identity mappedId) { + Properties generatorProps = Optional.ofNullable(mappedId) + .map(Identity::getProperties) + .orElse(new Properties()); + + if (!generatorProps.containsKey(SEGMENT_VALUE_PARAM)) { + String propertyName = context.getProperty().getName(); + + // Use the name we just ensured exists in BasicValueIdCreator + String entityName = (mappedId != null && mappedId.getName() != null) + ? mappedId.getName() + : "default"; + + generatorProps.put(SEGMENT_VALUE_PARAM, entityName + "." + propertyName); + } + + // Standard Pooled-lo defaults + if (!generatorProps.containsKey(INCREMENT_PARAM)) { + generatorProps.put(INCREMENT_PARAM, "50"); + } + if (!generatorProps.containsKey(OPT_PARAM)) { + generatorProps.put(OPT_PARAM, "pooled-lo"); + } + + // Fixes the "SQL to format should not be null" error + this.configure(context, generatorProps); + + // Ensures the hibernate_sequences table and initial rows are in the DDL +// this.registerExportables(context.getDatabase()); + } +} \ No newline at end of file
