Skip to content

Commit 4b6822a

Browse files
committed
HHH-18498 - Support for unnamed generators
HHH-18593 - Enforce GeneratedValue GenerationType HHH-18609 - Use UuidGenerator for GenerationType.UUID
1 parent 76df41f commit 4b6822a

File tree

45 files changed

+2646
-250
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2646
-250
lines changed

hibernate-core/src/main/java/org/hibernate/boot/internal/InFlightMetadataCollectorImpl.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
import org.hibernate.boot.model.internal.AnnotatedClassType;
4747
import org.hibernate.boot.model.internal.CreateKeySecondPass;
4848
import org.hibernate.boot.model.internal.FkSecondPass;
49-
import org.hibernate.boot.model.internal.IdGeneratorResolverSecondPass;
49+
import org.hibernate.boot.model.internal.IdBagIdGeneratorResolverSecondPass;
50+
import org.hibernate.boot.model.internal.IdGeneratorResolver;
5051
import org.hibernate.boot.model.internal.ImplicitToOneJoinTableSecondPass;
5152
import org.hibernate.boot.model.internal.OptionalDeterminationSecondPass;
5253
import org.hibernate.boot.model.internal.QuerySecondPass;
@@ -714,9 +715,14 @@ public void addIdentifierGenerator(IdentifierGeneratorDefinition generator) {
714715
throw new IllegalArgumentException( "ID generator object or name is null." );
715716
}
716717

718+
if ( generator.getName().isEmpty() ) {
719+
return;
720+
}
721+
717722
if ( defaultIdentifierGeneratorNames.contains( generator.getName() ) ) {
718723
return;
719724
}
725+
720726
final IdentifierGeneratorDefinition old = idGeneratorDefinitionMap.put( generator.getName(), generator );
721727
if ( old != null && !old.equals( generator ) ) {
722728
if ( bootstrapContext.getJpaCompliance().isGlobalGeneratorScopeEnabled() ) {
@@ -1675,7 +1681,7 @@ public Join locateJoin(Identifier tableName) {
16751681
}
16761682
}
16771683

1678-
private ArrayList<IdGeneratorResolverSecondPass> idGeneratorResolverSecondPassList;
1684+
private ArrayList<IdGeneratorResolver> idGeneratorResolverSecondPassList;
16791685
private ArrayList<SetBasicValueTypeSecondPass> setBasicValueTypeSecondPassList;
16801686
private ArrayList<AggregateComponentSecondPass> aggregateComponentSecondPassList;
16811687
private ArrayList<FkSecondPass> fkSecondPassList;
@@ -1696,8 +1702,8 @@ public void addSecondPass(SecondPass secondPass) {
16961702

16971703
@Override
16981704
public void addSecondPass(SecondPass secondPass, boolean onTopOfTheQueue) {
1699-
if ( secondPass instanceof IdGeneratorResolverSecondPass ) {
1700-
addIdGeneratorResolverSecondPass( (IdGeneratorResolverSecondPass) secondPass, onTopOfTheQueue );
1705+
if ( secondPass instanceof IdGeneratorResolver ) {
1706+
addIdGeneratorResolverSecondPass( (IdGeneratorResolver) secondPass, onTopOfTheQueue );
17011707
}
17021708
else if ( secondPass instanceof SetBasicValueTypeSecondPass ) {
17031709
addSetBasicValueTypeSecondPass( (SetBasicValueTypeSecondPass) secondPass, onTopOfTheQueue );
@@ -1764,7 +1770,7 @@ private void addAggregateComponentSecondPass(AggregateComponentSecondPass second
17641770
addSecondPass( secondPass, aggregateComponentSecondPassList, onTopOfTheQueue );
17651771
}
17661772

1767-
private void addIdGeneratorResolverSecondPass(IdGeneratorResolverSecondPass secondPass, boolean onTopOfTheQueue) {
1773+
private void addIdGeneratorResolverSecondPass(IdGeneratorResolver secondPass, boolean onTopOfTheQueue) {
17681774
if ( idGeneratorResolverSecondPassList == null ) {
17691775
idGeneratorResolverSecondPassList = new ArrayList<>();
17701776
}

hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotationBinder.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import static org.hibernate.boot.model.internal.AnnotatedClassType.EMBEDDABLE;
5050
import static org.hibernate.boot.model.internal.AnnotatedClassType.ENTITY;
5151
import static org.hibernate.boot.model.internal.FilterDefBinder.bindFilterDefs;
52-
import static org.hibernate.boot.model.internal.GeneratorBinder.buildGenerators;
5352
import static org.hibernate.boot.model.internal.GeneratorParameters.interpretSequenceGenerator;
5453
import static org.hibernate.boot.model.internal.GeneratorParameters.interpretTableGenerator;
5554
import static org.hibernate.boot.model.internal.InheritanceState.getInheritanceStateOfSuperEntity;
@@ -132,7 +131,7 @@ public static void bindPackage(ClassLoaderService cls, String packageName, Metad
132131
sourceContext( context ).getClassDetailsRegistry()
133132
.resolveClassDetails( pack.getName() + ".package-info" );
134133

135-
buildGenerators( packageInfoClassDetails, context );
134+
GeneratorBinder.registerGlobalGenerators( packageInfoClassDetails, context );
136135

137136
bindTypeDescriptorRegistrations( packageInfoClassDetails, context );
138137
bindEmbeddableInstantiatorRegistrations( packageInfoClassDetails, context );
@@ -218,9 +217,9 @@ public static void bindClass(
218217
bindConverterRegistrations( classDetails, context );
219218

220219
// try to find class level generators
221-
final Map<String, IdentifierGeneratorDefinition> generators = buildGenerators( classDetails, context );
220+
// GeneratorBinder.registerGlobalGenerators( classDetails, context );
222221
if ( context.getMetadataCollector().getClassType( classDetails ) == ENTITY ) {
223-
EntityBinder.bindEntityClass( classDetails, inheritanceStatePerClass, generators, context );
222+
EntityBinder.bindEntityClass( classDetails, inheritanceStatePerClass, context );
224223
}
225224
}
226225

hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@
169169
import static org.hibernate.boot.model.internal.BinderHelper.isPrimitive;
170170
import static org.hibernate.boot.model.internal.DialectOverridesAnnotationHelper.getOverridableAnnotation;
171171
import static org.hibernate.boot.model.internal.EmbeddableBinder.fillEmbeddable;
172-
import static org.hibernate.boot.model.internal.GeneratorBinder.buildGenerators;
172+
import static org.hibernate.boot.model.internal.GeneratorBinder.visitIdGeneratorDefinitions;
173173
import static org.hibernate.boot.model.internal.PropertyHolderBuilder.buildPropertyHolder;
174174
import static org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle.fromResultCheckStyle;
175175
import static org.hibernate.internal.util.ReflectHelper.getDefaultSupplier;
@@ -263,7 +263,6 @@ public static void bindCollection(
263263
PropertyHolder propertyHolder,
264264
Nullability nullability,
265265
PropertyData inferredData,
266-
Map<String, IdentifierGeneratorDefinition> classGenerators,
267266
EntityBinder entityBinder,
268267
boolean isIdentifierMapper,
269268
MetadataBuildingContext context,
@@ -358,9 +357,26 @@ public static void bindCollection(
358357

359358
if ( property.hasAnnotationUsage( CollectionId.class, sourceModelContext ) ) {
360359
//do not compute the generators unless necessary
361-
final HashMap<String, IdentifierGeneratorDefinition> localGenerators = new HashMap<>(classGenerators);
362-
localGenerators.putAll( buildGenerators( property, context ) );
363-
collectionBinder.setLocalGenerators( localGenerators );
360+
final HashMap<String, IdentifierGeneratorDefinition> availableGenerators = new HashMap<>();
361+
visitIdGeneratorDefinitions(
362+
property.getDeclaringType(),
363+
definition -> {
364+
if ( !definition.getName().isEmpty() ) {
365+
availableGenerators.put( definition.getName(), definition );
366+
}
367+
},
368+
context
369+
);
370+
visitIdGeneratorDefinitions(
371+
property,
372+
definition -> {
373+
if ( !definition.getName().isEmpty() ) {
374+
availableGenerators.put( definition.getName(), definition );
375+
}
376+
},
377+
context
378+
);
379+
collectionBinder.setLocalGenerators( availableGenerators );
364380

365381
}
366382
collectionBinder.bind();

hibernate-core/src/main/java/org/hibernate/boot/model/internal/EmbeddableBinder.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,6 @@ static Component fillEmbeddable(
461461
? Nullability.FORCED_NULL
462462
: ( isNullable ? Nullability.NO_CONSTRAINT : Nullability.FORCED_NOT_NULL ),
463463
propertyAnnotatedElement,
464-
Map.of(),
465464
entityBinder,
466465
isIdentifierMapper,
467466
isComponentEmbedded,
@@ -480,7 +479,6 @@ static Component fillEmbeddable(
480479
subholder,
481480
propertyAnnotatedElement,
482481
value,
483-
Map.of(),
484482
context
485483
);
486484
}

hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ private SourceModelBuildingContext getSourceModelContext() {
213213
public static void bindEntityClass(
214214
ClassDetails clazzToProcess,
215215
Map<ClassDetails, InheritanceState> inheritanceStates,
216-
Map<String, IdentifierGeneratorDefinition> generators,
217216
MetadataBuildingContext context) {
218217
if ( LOG.isDebugEnabled() ) {
219218
LOG.debugf( "Binding entity from annotated class: %s", clazzToProcess.getName() );
@@ -242,7 +241,7 @@ public static void bindEntityClass(
242241
inheritanceStates
243242
);
244243
entityBinder.handleInheritance( inheritanceState, superEntity, holder );
245-
entityBinder.handleIdentifier( holder, inheritanceStates, generators, inheritanceState );
244+
entityBinder.handleIdentifier( holder, inheritanceStates, inheritanceState );
246245

247246
final InFlightMetadataCollector collector = context.getMetadataCollector();
248247
if ( persistentClass instanceof RootClass rootClass ) {
@@ -396,7 +395,6 @@ private void applyTypeBinder(Annotation containingAnnotation, PersistentClass pe
396395
private void handleIdentifier(
397396
PropertyHolder propertyHolder,
398397
Map<ClassDetails, InheritanceState> inheritanceStates,
399-
Map<String, IdentifierGeneratorDefinition> generators,
400398
InheritanceState inheritanceState) {
401399
final ElementsToProcess elementsToProcess = inheritanceState.postProcess( persistentClass, this );
402400
final Set<String> idPropertiesIfIdClass = handleIdClass(
@@ -412,7 +410,6 @@ private void handleIdentifier(
412410
inheritanceState,
413411
context,
414412
propertyHolder,
415-
generators,
416413
idPropertiesIfIdClass,
417414
elementsToProcess,
418415
inheritanceStates
@@ -1032,7 +1029,6 @@ private void processIdPropertiesIfNotAlready(
10321029
InheritanceState inheritanceState,
10331030
MetadataBuildingContext context,
10341031
PropertyHolder propertyHolder,
1035-
Map<String, IdentifierGeneratorDefinition> generators,
10361032
Set<String> idPropertiesIfIdClass,
10371033
ElementsToProcess elementsToProcess,
10381034
Map<ClassDetails, InheritanceState> inheritanceStates) {
@@ -1063,7 +1059,6 @@ private void processIdPropertiesIfNotAlready(
10631059
? Nullability.FORCED_NULL
10641060
: Nullability.NO_CONSTRAINT,
10651061
propertyAnnotatedElement,
1066-
generators,
10671062
this,
10681063
false,
10691064
false,

0 commit comments

Comments
 (0)