diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Cache71Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Cache71Dialect.java index c5b7bbb704..04bf153cc6 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Cache71Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Cache71Dialect.java @@ -41,7 +41,6 @@ import org.hibernate.hql.spi.id.IdTableSupportStandardImpl; import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy; import org.hibernate.hql.spi.id.global.GlobalTemporaryTableBulkIdStrategy; import org.hibernate.hql.spi.id.local.AfterUseAction; -import org.hibernate.id.IdentityGenerator; import org.hibernate.internal.util.StringHelper; import org.hibernate.persister.entity.Lockable; import org.hibernate.sql.CacheJoinFragment; @@ -466,8 +465,8 @@ public class Cache71Dialect extends Dialect { } @Override - public Class getNativeIdentifierGeneratorClass() { - return IdentityGenerator.class; + public String getNativeIdentifierGeneratorStrategy() { + return "identity"; } // IDENTITY support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java index 55afc817df..2eff91bfaa 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java @@ -741,7 +741,9 @@ public abstract class Dialect implements ConversionContext { * Comes into play whenever the user specifies the native generator. * * @return The native generator class. + * @deprecated use {@link #getNativeIdentifierGeneratorStrategy()} instead */ + @Deprecated public Class getNativeIdentifierGeneratorClass() { if ( getIdentityColumnSupport().supportsIdentityColumns() ) { return IdentityGenerator.class; @@ -751,6 +753,22 @@ public abstract class Dialect implements ConversionContext { } } + /** + * Resolves the native generation strategy associated to this dialect. + *
+ * Comes into play whenever the user specifies the native generator. + * + * @return The native generator strategy. + */ + public String getNativeIdentifierGeneratorStrategy() { + if ( getIdentityColumnSupport().supportsIdentityColumns() ) { + return "identity"; + } + else { + return "sequence"; + } + } + // IDENTITY support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /** diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Oracle12cDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Oracle12cDialect.java index 509f84a620..c031ae765e 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Oracle12cDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Oracle12cDialect.java @@ -14,7 +14,6 @@ import org.hibernate.dialect.pagination.LimitHandler; import org.hibernate.dialect.pagination.SQL2008StandardLimitHandler; import org.hibernate.engine.config.spi.ConfigurationService; import org.hibernate.engine.config.spi.StandardConverters; -import org.hibernate.id.enhanced.SequenceStyleGenerator; import org.hibernate.service.ServiceRegistry; import org.hibernate.type.MaterializedBlobType; import org.hibernate.type.WrappedMaterializedBlobType; @@ -62,8 +61,8 @@ public class Oracle12cDialect extends Oracle10gDialect { } @Override - public Class getNativeIdentifierGeneratorClass() { - return SequenceStyleGenerator.class; + public String getNativeIdentifierGeneratorStrategy() { + return "sequence"; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL81Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL81Dialect.java index 562a37c65c..48edd57b70 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL81Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/PostgreSQL81Dialect.java @@ -37,7 +37,6 @@ import org.hibernate.hql.spi.id.IdTableSupportStandardImpl; import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy; import org.hibernate.hql.spi.id.local.AfterUseAction; import org.hibernate.hql.spi.id.local.LocalTemporaryTableBulkIdStrategy; -import org.hibernate.id.enhanced.SequenceStyleGenerator; import org.hibernate.internal.util.JdbcExceptionHelper; import org.hibernate.procedure.internal.PostgresCallableStatementSupport; import org.hibernate.procedure.spi.CallableStatementSupport; @@ -323,8 +322,8 @@ public class PostgreSQL81Dialect extends Dialect { } @Override - public Class getNativeIdentifierGeneratorClass() { - return SequenceStyleGenerator.class; + public String getNativeIdentifierGeneratorStrategy() { + return "sequence"; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/id/factory/internal/DefaultIdentifierGeneratorFactory.java b/hibernate-core/src/main/java/org/hibernate/id/factory/internal/DefaultIdentifierGeneratorFactory.java index e324fdbc81..71c153ae4b 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/factory/internal/DefaultIdentifierGeneratorFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/id/factory/internal/DefaultIdentifierGeneratorFactory.java @@ -13,7 +13,10 @@ import java.util.concurrent.ConcurrentHashMap; import org.hibernate.MappingException; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; +import org.hibernate.cfg.AvailableSettings; import org.hibernate.dialect.Dialect; +import org.hibernate.engine.config.spi.ConfigurationService; +import org.hibernate.engine.config.spi.StandardConverters; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.id.Assigned; import org.hibernate.id.Configurable; @@ -124,19 +127,17 @@ public class DefaultIdentifierGeneratorFactory @Override public Class getIdentifierGeneratorClass(String strategy) { - if ( "native".equals( strategy ) ) { - return getDialect().getNativeIdentifierGeneratorClass(); - } - if ( "hilo".equals( strategy ) ) { throw new UnsupportedOperationException( "Support for 'hilo' generator has been removed" ); } + String resolvedStrategy = "native".equals( strategy ) ? + getDialect().getNativeIdentifierGeneratorStrategy() : strategy; - Class generatorClass = generatorStrategyToClassNameMap.get( strategy ); + Class generatorClass = generatorStrategyToClassNameMap.get( resolvedStrategy ); try { if ( generatorClass == null ) { final ClassLoaderService cls = serviceRegistry.getService( ClassLoaderService.class ); - generatorClass = cls.classForName( strategy ); + generatorClass = cls.classForName( resolvedStrategy ); } } catch ( ClassLoadingException e ) { @@ -149,5 +150,16 @@ public class DefaultIdentifierGeneratorFactory public void injectServices(ServiceRegistryImplementor serviceRegistry) { this.serviceRegistry = serviceRegistry; this.dialect = serviceRegistry.getService( JdbcEnvironment.class ).getDialect(); + final ConfigurationService configService = serviceRegistry.getService( ConfigurationService.class ); + + final boolean useNewIdentifierGenerators = configService.getSetting( + AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, + StandardConverters.BOOLEAN, + true + ); + + if(!useNewIdentifierGenerators) { + register( "sequence", SequenceGenerator.class ); + } } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/id/Person.hbm.xml b/hibernate-core/src/test/java/org/hibernate/test/id/Person.hbm.xml index cca71c7b6f..30e56432ab 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/id/Person.hbm.xml +++ b/hibernate-core/src/test/java/org/hibernate/test/id/Person.hbm.xml @@ -13,7 +13,9 @@