diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java index df5319afaaa4..73a45c935e65 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/PropertyBinder.java @@ -54,6 +54,8 @@ import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.PropertyData; import org.hibernate.engine.OptimisticLockStyle; +import org.hibernate.id.IdentifierGenerator; +import org.hibernate.id.PersistentIdentifierGenerator; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.mapping.Collection; import org.hibernate.mapping.Component; @@ -1441,6 +1443,14 @@ static void processId( ? serviceRegistry.requireService( ManagedBeanRegistry.class ).getBeanContainer() : null; idValue.setCustomIdGeneratorCreator( identifierGeneratorCreator( idProperty, annotation, beanContainer ) ); + final Map parameters = new HashMap<>(); + parameters.put( PersistentIdentifierGenerator.TABLE, idValue.getTable().getName() ); + if ( idValue.getColumnSpan() == 1 ) { + parameters.put( PersistentIdentifierGenerator.PK, idValue.getColumns().get(0).getName() ); + } + // YUCK! but cannot think of a clean way to do this given the string-config based scheme + parameters.put( PersistentIdentifierGenerator.IDENTIFIER_NORMALIZER, context.getObjectNameNormalizer() ); + idValue.setIdentifierGeneratorParameters( parameters ); } else if ( !generatorAnnotations.isEmpty() ) { // idValue.setCustomGeneratorCreator( generatorCreator( idProperty, generatorAnnotation ) ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/naming/ObjectNameNormalizer.java b/hibernate-core/src/main/java/org/hibernate/boot/model/naming/ObjectNameNormalizer.java index 2e4d3d870f66..c12454cee041 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/naming/ObjectNameNormalizer.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/naming/ObjectNameNormalizer.java @@ -34,7 +34,7 @@ public Identifier normalizeIdentifierQuoting(String identifierText) { return database().toIdentifier( identifierText ); } - protected Database database() { + public Database database() { if ( database == null ) { database = getBuildingContext().getMetadataCollector().getDatabase(); } diff --git a/hibernate-core/src/main/java/org/hibernate/id/enhanced/SequenceStyleGenerator.java b/hibernate-core/src/main/java/org/hibernate/id/enhanced/SequenceStyleGenerator.java index 1e60c4ec7d10..5e482c70fe98 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/enhanced/SequenceStyleGenerator.java +++ b/hibernate-core/src/main/java/org/hibernate/id/enhanced/SequenceStyleGenerator.java @@ -15,6 +15,7 @@ import org.hibernate.HibernateException; import org.hibernate.MappingException; import org.hibernate.boot.model.naming.Identifier; +import org.hibernate.boot.model.naming.ObjectNameNormalizer; import org.hibernate.boot.model.relational.Database; import org.hibernate.boot.model.relational.QualifiedName; import org.hibernate.boot.model.relational.QualifiedNameParser; @@ -216,7 +217,8 @@ public void configure(Type type, Properties parameters, ServiceRegistry serviceR physicalSequence, optimizationStrategy, serviceRegistry, - determineContributor( parameters ) + determineContributor( parameters ), + (ObjectNameNormalizer) parameters.get( IDENTIFIER_NORMALIZER ) ); if ( physicalSequence @@ -251,7 +253,8 @@ private int adjustIncrementSize( boolean physicalSequence, OptimizerDescriptor optimizationStrategy, ServiceRegistry serviceRegistry, - String contributor) { + String contributor, + ObjectNameNormalizer normalizer) { final ConfigurationService configurationService = serviceRegistry.requireService( ConfigurationService.class ); final SequenceMismatchStrategy sequenceMismatchStrategy = configurationService.getSetting( AvailableSettings.SEQUENCE_INCREMENT_SIZE_MISMATCH_STRATEGY, @@ -262,7 +265,10 @@ private int adjustIncrementSize( if ( sequenceMismatchStrategy != SequenceMismatchStrategy.NONE && optimizationStrategy.isPooled() && physicalSequence ) { - final String databaseSequenceName = sequenceName.getObjectName().getText(); + final String databaseSequenceName = normalizer.database() + .getPhysicalNamingStrategy() + .toPhysicalSequenceName( sequenceName.getObjectName(), jdbcEnvironment ) + .getText(); final Number databaseIncrementValue = isSchemaToBeRecreated( contributor, configurationService ) ? null : getSequenceIncrementValue( jdbcEnvironment, databaseSequenceName ); if ( databaseIncrementValue != null && databaseIncrementValue.intValue() != incrementSize) { final int dbIncrementValue = databaseIncrementValue.intValue();