Skip to content

Commit 0eeb3d0

Browse files
committed
Add RuntimeModelCreationContext#getOrCreateIdGenerator() for Hibernate Reactive
1 parent bbfba45 commit 0eeb3d0

File tree

4 files changed

+33
-21
lines changed

4 files changed

+33
-21
lines changed

hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
import org.hibernate.jpa.internal.ExceptionMapperLegacyJpaImpl;
8585
import org.hibernate.jpa.internal.PersistenceUnitUtilImpl;
8686
import org.hibernate.mapping.GeneratorSettings;
87+
import org.hibernate.mapping.PersistentClass;
8788
import org.hibernate.mapping.RootClass;
8889
import org.hibernate.metamodel.MappingMetamodel;
8990
import org.hibernate.metamodel.RepresentationMode;
@@ -1811,5 +1812,26 @@ public String getDefaultSchema() {
18111812
public SqlStringGenerationContext getSqlStringGenerationContext() {
18121813
return sqlStringGenerationContext;
18131814
}
1815+
1816+
@Override
1817+
public Generator getOrCreateIdGenerator(String rootName, PersistentClass persistentClass) {
1818+
final var existing = getGenerators().get( rootName );
1819+
if ( existing != null ) {
1820+
return existing;
1821+
}
1822+
else {
1823+
final var idGenerator =
1824+
persistentClass.getIdentifier()
1825+
// returns the cached Generator if it was already created
1826+
.createGenerator(
1827+
getDialect(),
1828+
persistentClass.getRootClass(),
1829+
persistentClass.getIdentifierProperty(),
1830+
getGeneratorSettings()
1831+
);
1832+
getGenerators().put( rootName, idGenerator );
1833+
return idGenerator;
1834+
}
1835+
}
18141836
}
18151837
}

hibernate-core/src/main/java/org/hibernate/metamodel/spi/RuntimeModelCreationContext.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.hibernate.engine.spi.SessionFactoryImplementor;
1515
import org.hibernate.generator.Generator;
1616
import org.hibernate.mapping.GeneratorSettings;
17+
import org.hibernate.mapping.PersistentClass;
1718
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
1819
import org.hibernate.service.ServiceRegistry;
1920
import org.hibernate.type.descriptor.java.spi.JavaTypeRegistry;
@@ -65,4 +66,7 @@ default MetadataImplementor getMetadata() {
6566
Map<String, Generator> getGenerators();
6667

6768
GeneratorSettings getGeneratorSettings();
69+
70+
// For Hibernate Reactive
71+
Generator getOrCreateIdGenerator(String rootName, PersistentClass persistentClass);
6872
}

hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public EntityMetamodel(
155155
PersistentClass persistentClass,
156156
RuntimeModelCreationContext creationContext) {
157157
this( persistentClass, creationContext,
158-
rootName -> buildIdGenerator( rootName, persistentClass, creationContext ) );
158+
rootName -> creationContext.getOrCreateIdGenerator( rootName, persistentClass ) );
159159
}
160160

161161
/*
@@ -575,26 +575,6 @@ private static boolean writePropertyValue(OnExecutionGenerator generator) {
575575
return writePropertyValue;
576576
}
577577

578-
private static Generator buildIdGenerator(String rootName, PersistentClass persistentClass, RuntimeModelCreationContext creationContext) {
579-
final var existing = creationContext.getGenerators().get( rootName );
580-
if ( existing != null ) {
581-
return existing;
582-
}
583-
else {
584-
final var idGenerator =
585-
persistentClass.getIdentifier()
586-
// returns the cached Generator if it was already created
587-
.createGenerator(
588-
creationContext.getDialect(),
589-
persistentClass.getRootClass(),
590-
persistentClass.getIdentifierProperty(),
591-
creationContext.getGeneratorSettings()
592-
);
593-
creationContext.getGenerators().put( rootName, idGenerator );
594-
return idGenerator;
595-
}
596-
}
597-
598578
private void verifyNaturalIdProperty(Property property) {
599579
final var value = property.getValue();
600580
if ( value instanceof ManyToOne toOne ) {

hibernate-core/src/test/java/org/hibernate/orm/test/LocalTemporaryTableMutationStrategyNoDropTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.hibernate.engine.spi.SessionFactoryImplementor;
2424
import org.hibernate.generator.Generator;
2525
import org.hibernate.mapping.GeneratorSettings;
26+
import org.hibernate.mapping.PersistentClass;
2627
import org.hibernate.metamodel.spi.MappingMetamodelImplementor;
2728
import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
2829
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
@@ -209,5 +210,10 @@ public String getDefaultSchema() {
209210
public GeneratorSettings getGeneratorSettings() {
210211
return this;
211212
}
213+
214+
@Override
215+
public Generator getOrCreateIdGenerator(String rootName, PersistentClass persistentClass) {
216+
return null;
217+
}
212218
}
213219
}

0 commit comments

Comments
 (0)