Skip to content

Commit 1a4426a

Browse files
Temporarily add hints needed for Hibernate 7.2
See gh-48518 Co-Authored-By: Christoph Strobl <[email protected]>
1 parent 495467d commit 1a4426a

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed

module/spring-boot-hibernate/src/main/java/org/springframework/boot/hibernate/autoconfigure/HibernateJpaConfiguration.java

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,25 @@
2222
import java.util.LinkedHashMap;
2323
import java.util.List;
2424
import java.util.Map;
25+
import java.util.Set;
2526
import java.util.function.Consumer;
2627
import java.util.function.Supplier;
2728

2829
import javax.sql.DataSource;
2930

3031
import org.apache.commons.logging.Log;
3132
import org.apache.commons.logging.LogFactory;
33+
import org.hibernate.annotations.EmbeddedTable;
3234
import org.hibernate.boot.model.naming.ImplicitNamingStrategy;
3335
import org.hibernate.boot.model.naming.PhysicalNamingStrategy;
3436
import org.hibernate.boot.model.naming.PhysicalNamingStrategySnakeCaseImpl;
37+
import org.hibernate.boot.models.annotations.internal.EmbeddedTableAnnotation;
3538
import org.hibernate.cfg.ManagedBeanSettings;
39+
import org.hibernate.event.spi.PreFlushEventListener;
3640
import org.jspecify.annotations.Nullable;
3741

3842
import org.springframework.aot.hint.MemberCategory;
43+
import org.springframework.aot.hint.ReflectionHints;
3944
import org.springframework.aot.hint.RuntimeHints;
4045
import org.springframework.aot.hint.RuntimeHintsRegistrar;
4146
import org.springframework.aot.hint.TypeHint;
@@ -47,6 +52,7 @@
4752
import org.springframework.boot.context.properties.EnableConfigurationProperties;
4853
import org.springframework.boot.hibernate.SpringImplicitNamingStrategy;
4954
import org.springframework.boot.hibernate.SpringJtaPlatform;
55+
import org.springframework.boot.hibernate.autoconfigure.HibernateJpaConfiguration.Hibernate72RuntimeHints;
5056
import org.springframework.boot.hibernate.autoconfigure.HibernateJpaConfiguration.HibernateRuntimeHints;
5157
import org.springframework.boot.jdbc.SchemaManagementProvider;
5258
import org.springframework.boot.jdbc.metadata.CompositeDataSourcePoolMetadataProvider;
@@ -77,7 +83,7 @@
7783
@Configuration(proxyBeanMethods = false)
7884
@EnableConfigurationProperties(HibernateProperties.class)
7985
@ConditionalOnSingleCandidate(DataSource.class)
80-
@ImportRuntimeHints(HibernateRuntimeHints.class)
86+
@ImportRuntimeHints({ HibernateRuntimeHints.class, Hibernate72RuntimeHints.class })
8187
class HibernateJpaConfiguration extends JpaBaseConfiguration {
8288

8389
private static final Log logger = LogFactory.getLog(HibernateJpaConfiguration.class);
@@ -276,4 +282,67 @@ public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader)
276282

277283
}
278284

285+
static class Hibernate72RuntimeHints implements RuntimeHintsRegistrar {
286+
287+
@Override
288+
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
289+
registerLoggerHints(hints.reflection());
290+
registerEventHints(hints.reflection());
291+
registerAnnotationHints(hints.reflection());
292+
}
293+
294+
private void registerLoggerHints(ReflectionHints reflection) {
295+
reflection.registerTypes(Set.of(TypeReference.of("org.hibernate.action.internal.ActionLogging_$logger"),
296+
TypeReference.of("org.hibernate.boot.BootLogging_$logger"),
297+
TypeReference.of("org.hibernate.boot.beanvalidation.BeanValidationLogger_$logger"),
298+
TypeReference
299+
.of("org.hibernate.bytecode.enhance.spi.interceptor.BytecodeInterceptorLogging_$logger"),
300+
TypeReference.of("org.hibernate.collection.internal.CollectionLogger_$logger"),
301+
TypeReference.of("org.hibernate.context.internal.CurrentSessionLogging_$logger"),
302+
TypeReference.of("org.hibernate.engine.internal.NaturalIdLogging_$logger"),
303+
TypeReference.of("org.hibernate.engine.internal.PersistenceContextLogging_$logger"),
304+
TypeReference.of("org.hibernate.engine.internal.SessionMetricsLogger_$logger"),
305+
TypeReference.of("org.hibernate.engine.jdbc.JdbcLogging_$logger"),
306+
TypeReference.of("org.hibernate.engine.jdbc.batch.JdbcBatchLogging_$logger"),
307+
TypeReference
308+
.of("org.hibernate.engine.jdbc.connections.internal.ConnectionProviderLogging_$logger"),
309+
TypeReference.of("org.hibernate.engine.jdbc.env.internal.LobCreationLogging_$logger"),
310+
TypeReference.of("org.hibernate.engine.jdbc.spi.SQLExceptionLogging_$logger"),
311+
TypeReference.of("org.hibernate.event.internal.EntityCopyLogging_$logger"),
312+
TypeReference.of("org.hibernate.event.internal.EventListenerLogging_$logger"),
313+
TypeReference.of("org.hibernate.id.UUIDLogger_$logger"),
314+
TypeReference.of("org.hibernate.id.enhanced.OptimizerLogger_$logger"),
315+
TypeReference.of("org.hibernate.internal.SessionFactoryLogging_$logger"),
316+
TypeReference.of("org.hibernate.internal.SessionLogging_$logger"),
317+
TypeReference.of("org.hibernate.internal.log.StatisticsLogger_$logger"),
318+
TypeReference.of("org.hibernate.jpa.internal.JpaLogger_$logger"),
319+
TypeReference.of("org.hibernate.loader.ast.internal.MultiKeyLoadLogging_$logger"),
320+
TypeReference.of("org.hibernate.metamodel.mapping.MappingModelCreationLogging_$logger"),
321+
TypeReference.of("org.hibernate.query.QueryLogging_$logger"),
322+
TypeReference.of("org.hibernate.query.hql.HqlLogging_$logger"),
323+
TypeReference.of("org.hibernate.resource.jdbc.internal.LogicalConnectionLogging_$logger"),
324+
TypeReference.of("org.hibernate.resource.transaction.backend.jta.internal.JtaLogging_$logger"),
325+
TypeReference.of("org.hibernate.resource.transaction.internal.SynchronizationLogging_$logger"),
326+
TypeReference.of("org.hibernate.service.internal.ServiceLogger_$logger"),
327+
TypeReference.of("org.hibernate.sql.model.ModelMutationLogging_$logger"),
328+
TypeReference.of("org.hibernate.sql.results.graph.embeddable.EmbeddableLoadingLogger_$logger")),
329+
(hint) -> hint.withMembers(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
330+
MemberCategory.INVOKE_PUBLIC_METHODS));
331+
}
332+
333+
private void registerEventHints(ReflectionHints reflection) {
334+
reflection.registerType(PreFlushEventListener.class, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
335+
MemberCategory.INVOKE_PUBLIC_METHODS);
336+
reflection.registerType(PreFlushEventListener[].class, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
337+
MemberCategory.INVOKE_PUBLIC_METHODS);
338+
}
339+
340+
private void registerAnnotationHints(ReflectionHints reflection) {
341+
reflection.registerType(EmbeddedTable.class, MemberCategory.INVOKE_PUBLIC_METHODS);
342+
reflection.registerType(EmbeddedTableAnnotation.class, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS,
343+
MemberCategory.INVOKE_PUBLIC_METHODS);
344+
}
345+
346+
}
347+
279348
}

module/spring-boot-hibernate/src/test/java/org/springframework/boot/hibernate/autoconfigure/HibernateJpaAutoConfigurationTests.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import org.springframework.boot.hibernate.SpringImplicitNamingStrategy;
7272
import org.springframework.boot.hibernate.SpringJtaPlatform;
7373
import org.springframework.boot.hibernate.autoconfigure.HibernateJpaAutoConfigurationTests.JpaUsingApplicationListenerConfiguration.EventCapturingApplicationListener;
74+
import org.springframework.boot.hibernate.autoconfigure.HibernateJpaConfiguration.Hibernate72RuntimeHints;
7475
import org.springframework.boot.hibernate.autoconfigure.HibernateJpaConfiguration.HibernateRuntimeHints;
7576
import org.springframework.boot.jdbc.DataSourceBuilder;
7677
import org.springframework.boot.jdbc.autoconfigure.DataSourceAutoConfiguration;
@@ -876,6 +877,24 @@ void registersHintsForNamingClasses() {
876877
}
877878
}
878879

880+
@Test
881+
void registersHintsForHibernate72() {
882+
RuntimeHints hints = new RuntimeHints();
883+
new Hibernate72RuntimeHints().registerHints(hints, getClass().getClassLoader());
884+
assertThat(RuntimeHintsPredicates.reflection()
885+
.onType(TypeReference.of("org.hibernate.action.internal.ActionLogging_$logger"))
886+
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_PUBLIC_METHODS))
887+
.accepts(hints);
888+
assertThat(RuntimeHintsPredicates.reflection()
889+
.onType(TypeReference.of("org.hibernate.event.spi.PreFlushEventListener"))
890+
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_PUBLIC_METHODS))
891+
.accepts(hints);
892+
assertThat(RuntimeHintsPredicates.reflection()
893+
.onType(TypeReference.of("org.hibernate.boot.models.annotations.internal.EmbeddedTableAnnotation"))
894+
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS, MemberCategory.INVOKE_PUBLIC_METHODS))
895+
.accepts(hints);
896+
}
897+
879898
@Test
880899
@Disabled("gh-40177")
881900
void whenSpringJpaGenerateDdlIsNotSetThenTableIsNotCreated() {

0 commit comments

Comments
 (0)