HHH-18337 Account for physical naming strategy when querying db sequence
This commit is contained in:
parent
7c66788c93
commit
88bcc7140d
|
@ -54,6 +54,8 @@ import org.hibernate.boot.spi.InFlightMetadataCollector;
|
||||||
import org.hibernate.boot.spi.MetadataBuildingContext;
|
import org.hibernate.boot.spi.MetadataBuildingContext;
|
||||||
import org.hibernate.boot.spi.PropertyData;
|
import org.hibernate.boot.spi.PropertyData;
|
||||||
import org.hibernate.engine.OptimisticLockStyle;
|
import org.hibernate.engine.OptimisticLockStyle;
|
||||||
|
import org.hibernate.id.IdentifierGenerator;
|
||||||
|
import org.hibernate.id.PersistentIdentifierGenerator;
|
||||||
import org.hibernate.internal.CoreMessageLogger;
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
import org.hibernate.mapping.Collection;
|
import org.hibernate.mapping.Collection;
|
||||||
import org.hibernate.mapping.Component;
|
import org.hibernate.mapping.Component;
|
||||||
|
@ -1441,6 +1443,14 @@ public class PropertyBinder {
|
||||||
? serviceRegistry.requireService( ManagedBeanRegistry.class ).getBeanContainer()
|
? serviceRegistry.requireService( ManagedBeanRegistry.class ).getBeanContainer()
|
||||||
: null;
|
: null;
|
||||||
idValue.setCustomIdGeneratorCreator( identifierGeneratorCreator( idProperty, annotation, beanContainer ) );
|
idValue.setCustomIdGeneratorCreator( identifierGeneratorCreator( idProperty, annotation, beanContainer ) );
|
||||||
|
final Map<String,Object> 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() ) {
|
else if ( !generatorAnnotations.isEmpty() ) {
|
||||||
// idValue.setCustomGeneratorCreator( generatorCreator( idProperty, generatorAnnotation ) );
|
// idValue.setCustomGeneratorCreator( generatorCreator( idProperty, generatorAnnotation ) );
|
||||||
|
|
|
@ -34,7 +34,7 @@ public abstract class ObjectNameNormalizer {
|
||||||
return database().toIdentifier( identifierText );
|
return database().toIdentifier( identifierText );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Database database() {
|
public Database database() {
|
||||||
if ( database == null ) {
|
if ( database == null ) {
|
||||||
database = getBuildingContext().getMetadataCollector().getDatabase();
|
database = getBuildingContext().getMetadataCollector().getDatabase();
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ import java.util.Set;
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.boot.model.naming.Identifier;
|
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.Database;
|
||||||
import org.hibernate.boot.model.relational.QualifiedName;
|
import org.hibernate.boot.model.relational.QualifiedName;
|
||||||
import org.hibernate.boot.model.relational.QualifiedNameParser;
|
import org.hibernate.boot.model.relational.QualifiedNameParser;
|
||||||
|
@ -216,7 +217,8 @@ public class SequenceStyleGenerator
|
||||||
physicalSequence,
|
physicalSequence,
|
||||||
optimizationStrategy,
|
optimizationStrategy,
|
||||||
serviceRegistry,
|
serviceRegistry,
|
||||||
determineContributor( parameters )
|
determineContributor( parameters ),
|
||||||
|
(ObjectNameNormalizer) parameters.get( IDENTIFIER_NORMALIZER )
|
||||||
);
|
);
|
||||||
|
|
||||||
if ( physicalSequence
|
if ( physicalSequence
|
||||||
|
@ -251,7 +253,8 @@ public class SequenceStyleGenerator
|
||||||
boolean physicalSequence,
|
boolean physicalSequence,
|
||||||
OptimizerDescriptor optimizationStrategy,
|
OptimizerDescriptor optimizationStrategy,
|
||||||
ServiceRegistry serviceRegistry,
|
ServiceRegistry serviceRegistry,
|
||||||
String contributor) {
|
String contributor,
|
||||||
|
ObjectNameNormalizer normalizer) {
|
||||||
final ConfigurationService configurationService = serviceRegistry.requireService( ConfigurationService.class );
|
final ConfigurationService configurationService = serviceRegistry.requireService( ConfigurationService.class );
|
||||||
final SequenceMismatchStrategy sequenceMismatchStrategy = configurationService.getSetting(
|
final SequenceMismatchStrategy sequenceMismatchStrategy = configurationService.getSetting(
|
||||||
AvailableSettings.SEQUENCE_INCREMENT_SIZE_MISMATCH_STRATEGY,
|
AvailableSettings.SEQUENCE_INCREMENT_SIZE_MISMATCH_STRATEGY,
|
||||||
|
@ -262,7 +265,10 @@ public class SequenceStyleGenerator
|
||||||
if ( sequenceMismatchStrategy != SequenceMismatchStrategy.NONE
|
if ( sequenceMismatchStrategy != SequenceMismatchStrategy.NONE
|
||||||
&& optimizationStrategy.isPooled()
|
&& optimizationStrategy.isPooled()
|
||||||
&& physicalSequence ) {
|
&& 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 );
|
final Number databaseIncrementValue = isSchemaToBeRecreated( contributor, configurationService ) ? null : getSequenceIncrementValue( jdbcEnvironment, databaseSequenceName );
|
||||||
if ( databaseIncrementValue != null && databaseIncrementValue.intValue() != incrementSize) {
|
if ( databaseIncrementValue != null && databaseIncrementValue.intValue() != incrementSize) {
|
||||||
final int dbIncrementValue = databaseIncrementValue.intValue();
|
final int dbIncrementValue = databaseIncrementValue.intValue();
|
||||||
|
|
Loading…
Reference in New Issue