HHH-12454 - Offer flag to consider id generator with local scope (legacy non JPA behavior)
This commit is contained in:
parent
b463c809d6
commit
6cefa865b0
|
@ -71,6 +71,14 @@ hence we can save a database roundtrip.
|
|||
+
|
||||
If enabled Hibernate will initialize the entity Proxy even when accessing its identifier.
|
||||
|
||||
`*hibernate.jpa.compliance.global_id_generators*` (e.g. `true` or `false` (default value) )::
|
||||
The JPA spec says that the scope of TableGenerator and SequenceGenerator names is global to the persistence unit (across all generator types).
|
||||
+
|
||||
Traditionally, Hibernate has considered the names locally scoped.
|
||||
+
|
||||
If enabled, the names used by `@TableGenerator` and `@SequenceGenerator` will be considered global so configuring two different generators
|
||||
with the same name will cause a `java.lang.IllegalArgumentException' to be thrown at boot time.
|
||||
|
||||
[[configurations-database-connection]]
|
||||
=== Database connection properties
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ import org.hibernate.cache.spi.TimestampsCacheFactory;
|
|||
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
|
||||
import org.hibernate.dialect.function.SQLFunction;
|
||||
import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy;
|
||||
import org.hibernate.jpa.JpaCompliance;
|
||||
import org.hibernate.jpa.spi.JpaCompliance;
|
||||
import org.hibernate.loader.BatchFetchStyle;
|
||||
import org.hibernate.proxy.EntityNotFoundDelegate;
|
||||
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
|
||||
|
|
|
@ -36,6 +36,8 @@ import org.hibernate.cfg.AvailableSettings;
|
|||
import org.hibernate.cfg.annotations.reflection.JPAMetadataProvider;
|
||||
import org.hibernate.dialect.function.SQLFunction;
|
||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||
import org.hibernate.jpa.internal.JpaComplianceImpl;
|
||||
import org.hibernate.jpa.spi.MutableJpaCompliance;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
import org.jboss.jandex.IndexView;
|
||||
|
@ -51,6 +53,8 @@ public class BootstrapContextImpl implements BootstrapContext {
|
|||
|
||||
private final StandardServiceRegistry serviceRegistry;
|
||||
|
||||
private final MutableJpaCompliance jpaCompliance;
|
||||
|
||||
private final TypeConfiguration typeConfiguration;
|
||||
|
||||
private final ClassLoaderAccessImpl classLoaderAccess;
|
||||
|
@ -87,6 +91,7 @@ public class BootstrapContextImpl implements BootstrapContext {
|
|||
final StrategySelector strategySelector = serviceRegistry.getService( StrategySelector.class );
|
||||
final ConfigurationService configService = serviceRegistry.getService( ConfigurationService.class );
|
||||
|
||||
this.jpaCompliance = new JpaComplianceImpl( configService.getSettings(), false );
|
||||
this.scanOptions = new StandardScanOptions(
|
||||
(String) configService.getSettings().get( AvailableSettings.SCANNER_DISCOVERY ),
|
||||
false
|
||||
|
@ -112,6 +117,11 @@ public class BootstrapContextImpl implements BootstrapContext {
|
|||
return serviceRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MutableJpaCompliance getJpaCompliance() {
|
||||
return jpaCompliance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeConfiguration getTypeConfiguration() {
|
||||
return typeConfiguration;
|
||||
|
|
|
@ -51,7 +51,6 @@ import org.hibernate.boot.model.relational.Namespace;
|
|||
import org.hibernate.boot.model.relational.QualifiedTableName;
|
||||
import org.hibernate.boot.model.source.internal.ImplicitColumnNamingSecondPass;
|
||||
import org.hibernate.boot.model.source.spi.LocalMetadataBuildingContext;
|
||||
import org.hibernate.boot.model.convert.spi.ConverterAutoApplyHandler;
|
||||
import org.hibernate.boot.spi.BootstrapContext;
|
||||
import org.hibernate.boot.spi.InFlightMetadataCollector;
|
||||
import org.hibernate.boot.spi.MetadataBuildingContext;
|
||||
|
@ -60,6 +59,7 @@ import org.hibernate.boot.spi.NaturalIdUniqueKeyBinder;
|
|||
import org.hibernate.cache.cfg.internal.DomainDataRegionConfigImpl.Builder;
|
||||
import org.hibernate.cache.spi.access.AccessType;
|
||||
import org.hibernate.cfg.AnnotatedClassType;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.CopyIdentifierComponentSecondPass;
|
||||
import org.hibernate.cfg.CreateKeySecondPass;
|
||||
import org.hibernate.cfg.FkSecondPass;
|
||||
|
@ -493,11 +493,13 @@ public class InFlightMetadataCollectorImpl implements InFlightMetadataCollector
|
|||
return;
|
||||
}
|
||||
final IdentifierGeneratorDefinition old = idGeneratorDefinitionMap.put( generator.getName(), generator );
|
||||
if ( old != null ) {
|
||||
if ( !old.equals( generator ) ) {
|
||||
throw new IllegalArgumentException( "Duplicate generator name " + old.getName() );
|
||||
if ( old != null && !old.equals( generator ) ) {
|
||||
if ( bootstrapContext.getJpaCompliance().isGlobalGeneratorScopeEnabled() ) {
|
||||
throw new IllegalArgumentException( "Duplicate generator name " + old.getName() + " you will likely want to set the property " + AvailableSettings.JPA_ID_GENERATOR_GLOBAL_SCOPE_COMPLIANCE + " to false " );
|
||||
}
|
||||
else {
|
||||
log.duplicateGeneratorName( old.getName() );
|
||||
}
|
||||
// log.duplicateGeneratorName( old.getName() );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ import java.util.Map;
|
|||
import java.util.TimeZone;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.ConnectionAcquisitionMode;
|
||||
import org.hibernate.ConnectionReleaseMode;
|
||||
import org.hibernate.CustomEntityDirtinessStrategy;
|
||||
|
@ -51,8 +50,8 @@ import org.hibernate.id.UUIDGenerator;
|
|||
import org.hibernate.id.uuid.LocalObjectUuidHelper;
|
||||
import org.hibernate.internal.log.DeprecationLogger;
|
||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||
import org.hibernate.jpa.JpaCompliance;
|
||||
import org.hibernate.jpa.spi.JpaComplianceImpl;
|
||||
import org.hibernate.jpa.spi.JpaCompliance;
|
||||
import org.hibernate.jpa.spi.MutableJpaCompliance;
|
||||
import org.hibernate.loader.BatchFetchStyle;
|
||||
import org.hibernate.proxy.EntityNotFoundDelegate;
|
||||
import org.hibernate.query.ImmutableEntityUpdateQueryHandlingMode;
|
||||
|
@ -235,7 +234,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
|||
|
||||
private Map<String, SQLFunction> sqlFunctions;
|
||||
|
||||
private JpaComplianceImpl jpaCompliance;
|
||||
private MutableJpaCompliance jpaCompliance;
|
||||
|
||||
private boolean failOnPaginationOverCollectionFetchEnabled;
|
||||
|
||||
|
@ -465,7 +464,7 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
|||
);
|
||||
|
||||
// added the boolean parameter in case we want to define some form of "all" as discussed
|
||||
this.jpaCompliance = new JpaComplianceImpl( configurationSettings, false );
|
||||
this.jpaCompliance = context.getJpaCompliance();
|
||||
|
||||
this.failOnPaginationOverCollectionFetchEnabled = ConfigurationHelper.getBoolean(
|
||||
FAIL_ON_PAGINATION_OVER_COLLECTION_FETCH,
|
||||
|
@ -979,8 +978,6 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions {
|
|||
return jpaCompliance;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// In-flight mutation access
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ import org.hibernate.cfg.BaselineSessionEventsListenerBuilder;
|
|||
import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
|
||||
import org.hibernate.dialect.function.SQLFunction;
|
||||
import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy;
|
||||
import org.hibernate.jpa.JpaCompliance;
|
||||
import org.hibernate.jpa.spi.JpaCompliance;
|
||||
import org.hibernate.loader.BatchFetchStyle;
|
||||
import org.hibernate.proxy.EntityNotFoundDelegate;
|
||||
import org.hibernate.query.ImmutableEntityUpdateQueryHandlingMode;
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
package org.hibernate.boot.spi;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.annotations.common.reflection.ReflectionManager;
|
||||
|
@ -20,6 +19,7 @@ import org.hibernate.boot.internal.ClassmateContext;
|
|||
import org.hibernate.boot.model.relational.AuxiliaryDatabaseObject;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.dialect.function.SQLFunction;
|
||||
import org.hibernate.jpa.spi.MutableJpaCompliance;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
import org.jboss.jandex.IndexView;
|
||||
|
@ -34,6 +34,8 @@ import org.jboss.jandex.IndexView;
|
|||
public interface BootstrapContext {
|
||||
StandardServiceRegistry getServiceRegistry();
|
||||
|
||||
MutableJpaCompliance getJpaCompliance();
|
||||
|
||||
TypeConfiguration getTypeConfiguration();
|
||||
|
||||
MetadataBuildingOptions getMetadataBuildingOptions();
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
|
|||
import org.hibernate.dialect.function.SQLFunction;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy;
|
||||
import org.hibernate.jpa.JpaCompliance;
|
||||
import org.hibernate.jpa.spi.JpaCompliance;
|
||||
import org.hibernate.loader.BatchFetchStyle;
|
||||
import org.hibernate.proxy.EntityNotFoundDelegate;
|
||||
import org.hibernate.query.ImmutableEntityUpdateQueryHandlingMode;
|
||||
|
|
|
@ -9,6 +9,7 @@ package org.hibernate.cfg;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
@ -128,6 +129,7 @@ import org.hibernate.annotations.common.reflection.XProperty;
|
|||
import org.hibernate.boot.model.IdGeneratorStrategyInterpreter;
|
||||
import org.hibernate.boot.model.IdentifierGeneratorDefinition;
|
||||
import org.hibernate.boot.model.TypeDefinition;
|
||||
import org.hibernate.boot.spi.InFlightMetadataCollector;
|
||||
import org.hibernate.boot.spi.InFlightMetadataCollector.EntityTableXref;
|
||||
import org.hibernate.boot.spi.MetadataBuildingContext;
|
||||
import org.hibernate.cfg.annotations.CollectionBinder;
|
||||
|
@ -2242,20 +2244,33 @@ public final class AnnotationBinder {
|
|||
foreignGeneratorBuilder.setName( "Hibernate-local--foreign generator" );
|
||||
foreignGeneratorBuilder.setStrategy( "foreign" );
|
||||
foreignGeneratorBuilder.addParam( "property", mapsIdProperty.getPropertyName() );
|
||||
|
||||
final IdentifierGeneratorDefinition foreignGenerator = foreignGeneratorBuilder.build();
|
||||
// Map<String, IdentifierGeneratorDefinition> localGenerators = ( HashMap<String, IdentifierGeneratorDefinition> ) classGenerators.clone();
|
||||
// localGenerators.put( foreignGenerator.getName(), foreignGenerator );
|
||||
|
||||
SecondPass secondPass = new IdGeneratorResolverSecondPass(
|
||||
( SimpleValue ) propertyBinder.getValue(),
|
||||
property,
|
||||
foreignGenerator.getStrategy(),
|
||||
foreignGenerator.getName(),
|
||||
context,
|
||||
foreignGenerator
|
||||
);
|
||||
context.getMetadataCollector().addSecondPass( secondPass );
|
||||
if ( isGlobalGeneratorNameGlobal( context ) ) {
|
||||
SecondPass secondPass = new IdGeneratorResolverSecondPass(
|
||||
(SimpleValue) propertyBinder.getValue(),
|
||||
property,
|
||||
foreignGenerator.getStrategy(),
|
||||
foreignGenerator.getName(),
|
||||
context,
|
||||
foreignGenerator
|
||||
);
|
||||
context.getMetadataCollector().addSecondPass( secondPass );
|
||||
}
|
||||
else {
|
||||
Map<String, IdentifierGeneratorDefinition> localGenerators = (HashMap<String, IdentifierGeneratorDefinition>) classGenerators
|
||||
.clone();
|
||||
localGenerators.put( foreignGenerator.getName(), foreignGenerator );
|
||||
|
||||
BinderHelper.makeIdGenerator(
|
||||
(SimpleValue) propertyBinder.getValue(),
|
||||
property,
|
||||
foreignGenerator.getStrategy(),
|
||||
foreignGenerator.getName(),
|
||||
context,
|
||||
localGenerators
|
||||
);
|
||||
}
|
||||
}
|
||||
if ( isId ) {
|
||||
//components and regular basic types create SimpleValue objects
|
||||
|
@ -2313,6 +2328,10 @@ public final class AnnotationBinder {
|
|||
}
|
||||
}
|
||||
|
||||
private static boolean isGlobalGeneratorNameGlobal(MetadataBuildingContext context) {
|
||||
return context.getBootstrapContext().getJpaCompliance().isGlobalGeneratorScopeEnabled();
|
||||
}
|
||||
|
||||
private static boolean isToManyAssociationWithinEmbeddableCollection(PropertyHolder propertyHolder) {
|
||||
if(propertyHolder instanceof ComponentPropertyHolder) {
|
||||
ComponentPropertyHolder componentPropertyHolder = (ComponentPropertyHolder) propertyHolder;
|
||||
|
@ -2344,10 +2363,6 @@ public final class AnnotationBinder {
|
|||
}
|
||||
XClass entityXClass = inferredData.getClassOrElement();
|
||||
XProperty idXProperty = inferredData.getProperty();
|
||||
//clone classGenerator and override with local values
|
||||
// HashMap<String, IdentifierGeneratorDefinition> localGenerators = ( HashMap<String, IdentifierGeneratorDefinition> ) classGenerators.clone();
|
||||
// localGenerators.putAll( buildGenerators( idXProperty, buildingContext ) );
|
||||
buildGenerators( idXProperty, buildingContext );
|
||||
|
||||
//manage composite related metadata
|
||||
//guess if its a component and find id data access (property, field etc)
|
||||
|
@ -2366,14 +2381,31 @@ public final class AnnotationBinder {
|
|||
generatorType = "assigned";
|
||||
}
|
||||
|
||||
SecondPass secondPass = new IdGeneratorResolverSecondPass(
|
||||
idValue,
|
||||
idXProperty,
|
||||
generatorType,
|
||||
generatorName,
|
||||
buildingContext
|
||||
);
|
||||
buildingContext.getMetadataCollector().addSecondPass( secondPass );
|
||||
if ( isGlobalGeneratorNameGlobal( buildingContext ) ) {
|
||||
buildGenerators( idXProperty, buildingContext );
|
||||
SecondPass secondPass = new IdGeneratorResolverSecondPass(
|
||||
idValue,
|
||||
idXProperty,
|
||||
generatorType,
|
||||
generatorName,
|
||||
buildingContext
|
||||
);
|
||||
buildingContext.getMetadataCollector().addSecondPass( secondPass );
|
||||
}
|
||||
else {
|
||||
//clone classGenerator and override with local values
|
||||
HashMap<String, IdentifierGeneratorDefinition> localGenerators = (HashMap<String, IdentifierGeneratorDefinition>) classGenerators
|
||||
.clone();
|
||||
localGenerators.putAll( buildGenerators( idXProperty, buildingContext ) );
|
||||
BinderHelper.makeIdGenerator(
|
||||
idValue,
|
||||
idXProperty,
|
||||
generatorType,
|
||||
generatorName,
|
||||
buildingContext,
|
||||
localGenerators
|
||||
);
|
||||
}
|
||||
|
||||
if ( LOG.isTraceEnabled() ) {
|
||||
LOG.tracev( "Bind {0} on {1}", ( isComponent ? "@EmbeddedId" : "@Id" ), inferredData.getPropertyName() );
|
||||
|
@ -2710,27 +2742,38 @@ public final class AnnotationBinder {
|
|||
XProperty property = propertyAnnotatedElement.getProperty();
|
||||
if ( property.isAnnotationPresent( GeneratedValue.class ) &&
|
||||
property.isAnnotationPresent( Id.class ) ) {
|
||||
//clone classGenerator and override with local values
|
||||
// Map<String, IdentifierGeneratorDefinition> localGenerators = new HashMap<>();
|
||||
// localGenerators.putAll( buildGenerators( property, buildingContext ) );
|
||||
|
||||
buildGenerators( property, buildingContext );
|
||||
GeneratedValue generatedValue = property.getAnnotation( GeneratedValue.class );
|
||||
String generatorType = generatedValue != null
|
||||
? generatorType( generatedValue, buildingContext, property.getType() )
|
||||
: "assigned";
|
||||
String generator = generatedValue != null ? generatedValue.generator() : BinderHelper.ANNOTATION_STRING_DEFAULT;
|
||||
String generator = generatedValue != null ?
|
||||
generatedValue.generator() :
|
||||
BinderHelper.ANNOTATION_STRING_DEFAULT;
|
||||
|
||||
SecondPass secondPass = new IdGeneratorResolverSecondPass(
|
||||
( SimpleValue ) comp.getProperty( property.getName() ).getValue(),
|
||||
property,
|
||||
generatorType,
|
||||
generator,
|
||||
buildingContext
|
||||
);
|
||||
buildingContext.getMetadataCollector().addSecondPass( secondPass );
|
||||
if ( isGlobalGeneratorNameGlobal( buildingContext ) ) {
|
||||
buildGenerators( property, buildingContext );
|
||||
SecondPass secondPass = new IdGeneratorResolverSecondPass(
|
||||
(SimpleValue) comp.getProperty( property.getName() ).getValue(),
|
||||
property,
|
||||
generatorType,
|
||||
generator,
|
||||
buildingContext
|
||||
);
|
||||
buildingContext.getMetadataCollector().addSecondPass( secondPass );
|
||||
}
|
||||
else {
|
||||
Map<String, IdentifierGeneratorDefinition> localGenerators = new HashMap<>();
|
||||
localGenerators.putAll( buildGenerators( property, buildingContext ) );
|
||||
BinderHelper.makeIdGenerator(
|
||||
(SimpleValue) comp.getProperty( property.getName() ).getValue(),
|
||||
property,
|
||||
generatorType,
|
||||
generator,
|
||||
buildingContext,
|
||||
localGenerators
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return comp;
|
||||
}
|
||||
|
@ -2827,14 +2870,26 @@ public final class AnnotationBinder {
|
|||
id = value.make();
|
||||
}
|
||||
rootClass.setIdentifier( id );
|
||||
SecondPass secondPass = new IdGeneratorResolverSecondPass(
|
||||
id,
|
||||
inferredData.getProperty(),
|
||||
generatorType,
|
||||
generatorName,
|
||||
buildingContext
|
||||
);
|
||||
buildingContext.getMetadataCollector().addSecondPass( secondPass );
|
||||
if ( isGlobalGeneratorNameGlobal( buildingContext ) ) {
|
||||
SecondPass secondPass = new IdGeneratorResolverSecondPass(
|
||||
id,
|
||||
inferredData.getProperty(),
|
||||
generatorType,
|
||||
generatorName,
|
||||
buildingContext
|
||||
);
|
||||
buildingContext.getMetadataCollector().addSecondPass( secondPass );
|
||||
}
|
||||
else {
|
||||
BinderHelper.makeIdGenerator(
|
||||
id,
|
||||
inferredData.getProperty(),
|
||||
generatorType,
|
||||
generatorName,
|
||||
buildingContext,
|
||||
Collections.emptyMap()
|
||||
);
|
||||
}
|
||||
|
||||
if ( isEmbedded ) {
|
||||
rootClass.setEmbeddedIdentifier( inferredData.getPropertyClass() == null );
|
||||
|
@ -3331,6 +3386,7 @@ public final class AnnotationBinder {
|
|||
}
|
||||
|
||||
private static HashMap<String, IdentifierGeneratorDefinition> buildGenerators(XAnnotatedElement annElt, MetadataBuildingContext context) {
|
||||
InFlightMetadataCollector metadataCollector = context.getMetadataCollector();
|
||||
HashMap<String, IdentifierGeneratorDefinition> generators = new HashMap<>();
|
||||
|
||||
TableGenerators tableGenerators = annElt.getAnnotation( TableGenerators.class );
|
||||
|
@ -3344,6 +3400,7 @@ public final class AnnotationBinder {
|
|||
idGenerator.getName(),
|
||||
idGenerator
|
||||
);
|
||||
metadataCollector.addIdentifierGenerator( idGenerator );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3358,6 +3415,7 @@ public final class AnnotationBinder {
|
|||
idGenerator.getName(),
|
||||
idGenerator
|
||||
);
|
||||
metadataCollector.addIdentifierGenerator( idGenerator );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3367,20 +3425,19 @@ public final class AnnotationBinder {
|
|||
if ( tabGen != null ) {
|
||||
IdentifierGeneratorDefinition idGen = buildIdGenerator( tabGen, context );
|
||||
generators.put( idGen.getName(), idGen );
|
||||
metadataCollector.addIdentifierGenerator( idGen );
|
||||
|
||||
}
|
||||
if ( seqGen != null ) {
|
||||
IdentifierGeneratorDefinition idGen = buildIdGenerator( seqGen, context );
|
||||
generators.put( idGen.getName(), idGen );
|
||||
metadataCollector.addIdentifierGenerator( idGen );
|
||||
}
|
||||
if ( genGen != null ) {
|
||||
IdentifierGeneratorDefinition idGen = buildIdGenerator( genGen, context );
|
||||
generators.put( idGen.getName(), idGen );
|
||||
metadataCollector.addIdentifierGenerator( idGen );
|
||||
}
|
||||
|
||||
generators.forEach( (name, idGenerator) -> {
|
||||
context.getMetadataCollector().addIdentifierGenerator( idGenerator );
|
||||
} );
|
||||
|
||||
return generators;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ import org.hibernate.boot.MetadataBuilder;
|
|||
import org.hibernate.boot.registry.classloading.internal.TcclLookupPrecedence;
|
||||
import org.hibernate.cache.spi.TimestampsCacheFactory;
|
||||
import org.hibernate.internal.log.DeprecationLogger;
|
||||
import org.hibernate.jpa.JpaCompliance;
|
||||
import org.hibernate.jpa.spi.JpaCompliance;
|
||||
import org.hibernate.query.ImmutableEntityUpdateQueryHandlingMode;
|
||||
import org.hibernate.query.internal.ParameterMetadataImpl;
|
||||
import org.hibernate.resource.beans.container.spi.ExtendedBeanManager;
|
||||
|
@ -1846,6 +1846,18 @@ public interface AvailableSettings extends org.hibernate.jpa.AvailableSettings {
|
|||
*/
|
||||
String JPA_CACHING_COMPLIANCE = "hibernate.jpa.compliance.caching";
|
||||
|
||||
/**
|
||||
* Determine if the scope of {@link javax.persistence.TableGenerator#name()} and {@link javax.persistence.SequenceGenerator#name()} should be
|
||||
* considered globally or locally defined.
|
||||
*
|
||||
* If enabled, the names will considered globally scoped so defining two different generators with the same name
|
||||
* will cause a name collision and an exception will be thrown during the bootstrap phase.
|
||||
*
|
||||
* @see JpaCompliance#isGlobalGeneratorScopeEnabled()
|
||||
* @since 5.2.17
|
||||
*/
|
||||
String JPA_ID_GENERATOR_GLOBAL_SCOPE_COMPLIANCE = "hibernate.jpa.compliance.global_id_generators";
|
||||
|
||||
/**
|
||||
* True/False setting indicating if the value stored in the table used by the {@link javax.persistence.TableGenerator}
|
||||
* is the last value generated or the next value to be used.
|
||||
|
|
|
@ -107,14 +107,26 @@ public class IdBagBinder extends BagBinder {
|
|||
generatorType = null;
|
||||
}
|
||||
|
||||
SecondPass secondPass = new IdGeneratorResolverSecondPass(
|
||||
id,
|
||||
property,
|
||||
generatorType,
|
||||
generator,
|
||||
getBuildingContext()
|
||||
);
|
||||
buildingContext.getMetadataCollector().addSecondPass( secondPass );
|
||||
if ( buildingContext.getBootstrapContext().getJpaCompliance().isGlobalGeneratorScopeEnabled() ) {
|
||||
SecondPass secondPass = new IdGeneratorResolverSecondPass(
|
||||
id,
|
||||
property,
|
||||
generatorType,
|
||||
generator,
|
||||
getBuildingContext()
|
||||
);
|
||||
buildingContext.getMetadataCollector().addSecondPass( secondPass );
|
||||
}
|
||||
else {
|
||||
BinderHelper.makeIdGenerator(
|
||||
id,
|
||||
property,
|
||||
generatorType,
|
||||
generator,
|
||||
getBuildingContext(),
|
||||
localGenerators
|
||||
);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import org.hibernate.TransactionException;
|
|||
import org.hibernate.engine.spi.ExceptionConverter;
|
||||
import org.hibernate.engine.transaction.spi.TransactionImplementor;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
import org.hibernate.jpa.JpaCompliance;
|
||||
import org.hibernate.jpa.spi.JpaCompliance;
|
||||
import org.hibernate.resource.transaction.spi.TransactionCoordinator;
|
||||
import org.hibernate.resource.transaction.spi.TransactionStatus;
|
||||
|
||||
|
|
|
@ -4,24 +4,25 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.jpa.spi;
|
||||
package org.hibernate.jpa.internal;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||
import org.hibernate.jpa.JpaCompliance;
|
||||
import org.hibernate.jpa.spi.MutableJpaCompliance;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class JpaComplianceImpl implements JpaCompliance {
|
||||
public class JpaComplianceImpl implements MutableJpaCompliance {
|
||||
private boolean queryCompliance;
|
||||
private boolean transactionCompliance;
|
||||
private boolean listCompliance;
|
||||
private boolean closedCompliance;
|
||||
private boolean proxyCompliance;
|
||||
private boolean cachingCompliance;
|
||||
private final boolean globalGeneratorNameScopeCompliance;
|
||||
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
|
@ -58,6 +59,11 @@ public class JpaComplianceImpl implements JpaCompliance {
|
|||
configurationSettings,
|
||||
jpaByDefault
|
||||
);
|
||||
globalGeneratorNameScopeCompliance = ConfigurationHelper.getBoolean(
|
||||
AvailableSettings.JPA_ID_GENERATOR_GLOBAL_SCOPE_COMPLIANCE,
|
||||
configurationSettings,
|
||||
jpaByDefault
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -90,6 +96,11 @@ public class JpaComplianceImpl implements JpaCompliance {
|
|||
return cachingCompliance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGlobalGeneratorScopeEnabled() {
|
||||
return globalGeneratorNameScopeCompliance;
|
||||
}
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Mutators
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.jpa;
|
||||
package org.hibernate.jpa.spi;
|
||||
|
||||
import org.hibernate.Transaction;
|
||||
|
||||
|
@ -89,4 +89,12 @@ public interface JpaCompliance {
|
|||
* @return {@code true} says to act the spec-defined way.
|
||||
*/
|
||||
boolean isJpaCacheComplianceEnabled();
|
||||
|
||||
/**
|
||||
* Should the the scope of {@link javax.persistence.TableGenerator#name()} and {@link javax.persistence.SequenceGenerator#name()} be
|
||||
* considered globally or locally defined?
|
||||
*
|
||||
* @return {@code true} indicates the generator name scope is considered global.
|
||||
*/
|
||||
boolean isGlobalGeneratorScopeEnabled();
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.jpa.spi;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public interface MutableJpaCompliance extends JpaCompliance {
|
||||
void setQueryCompliance(boolean queryCompliance);
|
||||
|
||||
void setTransactionCompliance(boolean transactionCompliance);
|
||||
|
||||
void setListCompliance(boolean listCompliance);
|
||||
|
||||
void setClosedCompliance(boolean closedCompliance);
|
||||
|
||||
void setProxyCompliance(boolean proxyCompliance);
|
||||
|
||||
void setCachingCompliance(boolean cachingCompliance);
|
||||
}
|
|
@ -15,7 +15,7 @@ import org.hibernate.engine.jdbc.spi.JdbcServices;
|
|||
import org.hibernate.engine.transaction.spi.IsolationDelegate;
|
||||
import org.hibernate.engine.transaction.spi.TransactionObserver;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.jpa.JpaCompliance;
|
||||
import org.hibernate.jpa.spi.JpaCompliance;
|
||||
import org.hibernate.resource.jdbc.spi.JdbcSessionOwner;
|
||||
import org.hibernate.resource.transaction.backend.jdbc.spi.JdbcResourceTransaction;
|
||||
import org.hibernate.resource.transaction.backend.jdbc.spi.JdbcResourceTransactionAccess;
|
||||
|
|
|
@ -19,7 +19,7 @@ import org.hibernate.engine.jdbc.spi.JdbcServices;
|
|||
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
|
||||
import org.hibernate.engine.transaction.spi.IsolationDelegate;
|
||||
import org.hibernate.engine.transaction.spi.TransactionObserver;
|
||||
import org.hibernate.jpa.JpaCompliance;
|
||||
import org.hibernate.jpa.spi.JpaCompliance;
|
||||
import org.hibernate.resource.jdbc.spi.JdbcSessionContext;
|
||||
import org.hibernate.resource.jdbc.spi.JdbcSessionOwner;
|
||||
import org.hibernate.resource.transaction.TransactionRequiredForJoinException;
|
||||
|
|
|
@ -8,7 +8,7 @@ package org.hibernate.resource.transaction.spi;
|
|||
|
||||
import org.hibernate.engine.transaction.spi.IsolationDelegate;
|
||||
import org.hibernate.engine.transaction.spi.TransactionObserver;
|
||||
import org.hibernate.jpa.JpaCompliance;
|
||||
import org.hibernate.jpa.spi.JpaCompliance;
|
||||
|
||||
/**
|
||||
* Models the coordination of all transaction related flows.
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
*/
|
||||
package org.hibernate.jpa;
|
||||
|
||||
import org.hibernate.jpa.spi.JpaCompliance;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
|
@ -44,6 +46,7 @@ public class JpaComplianceTestingImpl implements JpaCompliance {
|
|||
private boolean closedCompliance;
|
||||
private boolean proxyCompliance;
|
||||
private boolean cacheCompliance;
|
||||
private boolean idGeneratorNameScopeCompliance;
|
||||
|
||||
@Override
|
||||
public boolean isJpaQueryComplianceEnabled() {
|
||||
|
@ -74,4 +77,9 @@ public class JpaComplianceTestingImpl implements JpaCompliance {
|
|||
public boolean isJpaCacheComplianceEnabled() {
|
||||
return cacheCompliance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGlobalGeneratorScopeEnabled() {
|
||||
return idGeneratorNameScopeCompliance;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.hibernate.boot.spi.BootstrapContext;
|
|||
import org.hibernate.boot.spi.ClassLoaderAccess;
|
||||
import org.hibernate.boot.spi.MetadataBuildingOptions;
|
||||
import org.hibernate.dialect.function.SQLFunction;
|
||||
import org.hibernate.jpa.spi.MutableJpaCompliance;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
import org.jboss.jandex.IndexView;
|
||||
|
@ -48,6 +49,11 @@ public class BootstrapContextImpl implements BootstrapContext {
|
|||
return delegate.getServiceRegistry();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MutableJpaCompliance getJpaCompliance() {
|
||||
return delegate.getJpaCompliance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeConfiguration getTypeConfiguration() {
|
||||
return delegate.getTypeConfiguration();
|
||||
|
|
|
@ -42,48 +42,6 @@ For backward compatibility, a new setting called `hibernate.id.generator.stored_
|
|||
Existing applications migrating to 5.3 and using the `@TableGenerator` have to set the `hibernate.id.generator.stored_last_used` configuration property to `false`.
|
||||
====
|
||||
|
||||
=== Change in the `@TableGenerator` and `@SequenceGenerator` name scope
|
||||
|
||||
In order to be compliant with the JPA specification, generators names are now considered global (e.g. https://hibernate.atlassian.net/browse/HHH-12157[HHH-12157]) .
|
||||
Configuring two generators, even if with different types but with the same name will now cause a `java.lang.IllegalArgumentException' to be thrown at boot time.
|
||||
|
||||
For example, the following mappings are no longer valid:
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@Entity
|
||||
@TableGenerator(name = "ID_GENERATOR", ... )
|
||||
public class FirstEntity {
|
||||
....
|
||||
}
|
||||
|
||||
@Entity
|
||||
@TableGenerator(name = "ID_GENERATOR", ... )
|
||||
public class SecondEntity {
|
||||
....
|
||||
}
|
||||
----
|
||||
|
||||
or
|
||||
|
||||
[source,java]
|
||||
----
|
||||
@Entity
|
||||
@TableGenerator(name = "ID_GENERATOR", ... )
|
||||
public class FirstEntity {
|
||||
....
|
||||
}
|
||||
|
||||
@Entity
|
||||
@SequenceGenerator(name="ID_GENERATOR", ... )
|
||||
public class SecondEntity {
|
||||
....
|
||||
}
|
||||
----
|
||||
|
||||
The solution is to make all generators unique so that there are no two generators with the same name.
|
||||
|
||||
|
||||
=== Drop hibernate-infinispan module
|
||||
|
||||
Support for using Infinispan as a Hibernate 2nd-level cache provider has been moved to the Infinispan project so
|
||||
|
|
Loading…
Reference in New Issue