From 123acaa33a1096c44658398e33cf5a51f2718a36 Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Thu, 16 Jan 2025 16:50:24 +0200 Subject: [PATCH] Register Hibernate service providers for native run-time access Relates to https://github.com/quarkusio/quarkus/issues/41995 --- .../hibernate/orm/deployment/ClassNames.java | 18 ++++++++++++++++++ .../orm/deployment/HibernateOrmProcessor.java | 7 ++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/ClassNames.java b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/ClassNames.java index f7e6bd6d5f620..aca0343ec32d9 100644 --- a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/ClassNames.java +++ b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/ClassNames.java @@ -465,4 +465,22 @@ private static DotName createConstant(String fqcn) { "io.quarkus.hibernate.orm.deployment.HibernateUserTypeProcessor"); public static final DotName GRAAL_VM_FEATURES = createConstant("io.quarkus.hibernate.orm.deployment.GraalVMFeatures"); + + public static final List SERVICE_PROVIDERS = List.of( + // Accessed in org.hibernate.query.sqm.internal.SqmCriteriaNodeBuilder. + createConstant("org.hibernate.query.criteria.spi.CriteriaBuilderExtension"), + // Accessed in io.quarkus.hibernate.orm.runtime.customized.QuarkusIntegratorServiceImpl. + createConstant("org.hibernate.integrator.spi.Integrator"), + // Accessed in io.quarkus.hibernate.orm.runtime.customized.QuarkusStrategySelectorBuilder.buildSelector + createConstant("org.hibernate.boot.registry.selector.StrategyRegistrationProvider"), + // Accessed in io.quarkus.hibernate.orm.runtime.recording.RecordableBootstrap.applyServiceContributors + createConstant("org.hibernate.service.spi.ServiceContributor"), + // Accessed in org.hibernate.internal.FastSessionServices. + createConstant("org.hibernate.event.spi.EventManager"), + // Accessed in org.hibernate.query.internal.QueryEngineImpl.sortedFunctionContributors + createConstant("org.hibernate.boot.model.FunctionContributor"), + // Accessed in org.hibernate.event.spi.EventEngine. + createConstant("org.hibernate.event.spi.EventEngineContributor"), + // Accessed in org.hibernate.service.internal.SessionFactoryServiceRegistryFactoryImpl.buildServiceRegistry + createConstant("org.hibernate.service.spi.SessionFactoryServiceContributor")); } diff --git a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java index 2c518fbd575d5..1ecb454e5f2cb 100644 --- a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java +++ b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmProcessor.java @@ -104,6 +104,7 @@ import io.quarkus.deployment.builditem.nativeimage.NativeImageProxyDefinitionBuildItem; import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem; import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem; +import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem; import io.quarkus.deployment.index.IndexingUtil; import io.quarkus.deployment.pkg.steps.NativeOrNativeSourcesBuild; import io.quarkus.deployment.recording.RecorderContext; @@ -163,7 +164,11 @@ public final class HibernateOrmProcessor { private static final String INTEGRATOR_SERVICE_FILE = "META-INF/services/org.hibernate.integrator.spi.Integrator"; @BuildStep - NativeImageFeatureBuildItem registerServicesForReflection() { + NativeImageFeatureBuildItem registerServicesForReflection(BuildProducer services) { + for (DotName serviceProvider : ClassNames.SERVICE_PROVIDERS) { + services.produce(ServiceProviderBuildItem.allProvidersFromClassPath(serviceProvider.toString())); + } + return new NativeImageFeatureBuildItem(RegisterServicesForReflectionFeature.class); }