Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make methods of reachable hibernate services reflectively queryable #45649

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
import io.quarkus.deployment.builditem.LaunchModeBuildItem;
import io.quarkus.deployment.builditem.LiveReloadBuildItem;
import io.quarkus.deployment.builditem.LogCategoryBuildItem;
import io.quarkus.deployment.builditem.NativeImageFeatureBuildItem;
import io.quarkus.deployment.builditem.ServiceStartBuildItem;
import io.quarkus.deployment.builditem.SystemPropertyBuildItem;
import io.quarkus.deployment.builditem.TransformedClassesBuildItem;
Expand Down Expand Up @@ -125,6 +126,7 @@
import io.quarkus.hibernate.orm.runtime.boot.xml.RecordableXmlMapping;
import io.quarkus.hibernate.orm.runtime.config.DialectVersions;
import io.quarkus.hibernate.orm.runtime.dev.HibernateOrmDevIntegrator;
import io.quarkus.hibernate.orm.runtime.graal.RegisterServicesForReflectionFeature;
import io.quarkus.hibernate.orm.runtime.integration.HibernateOrmIntegrationStaticDescriptor;
import io.quarkus.hibernate.orm.runtime.migration.MultiTenancyStrategy;
import io.quarkus.hibernate.orm.runtime.proxies.PreGeneratedProxies;
Expand Down Expand Up @@ -160,6 +162,11 @@ public final class HibernateOrmProcessor {

private static final String INTEGRATOR_SERVICE_FILE = "META-INF/services/org.hibernate.integrator.spi.Integrator";

@BuildStep
NativeImageFeatureBuildItem registerServicesForReflection() {
return new NativeImageFeatureBuildItem(RegisterServicesForReflectionFeature.class);
}

@BuildStep
void registerHibernateOrmMetadataForCoreDialects(
BuildProducer<DatabaseKindDialectBuildItem> producer) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.quarkus.hibernate.orm.runtime.graal;

import java.util.HashSet;
import java.util.Set;

import org.graalvm.nativeimage.hosted.Feature;
import org.graalvm.nativeimage.hosted.RuntimeReflection;

/**
* Makes methods of reachable hibernate services accessible through {@link Class#getMethods()}.
*
* See <a href="https://github.com/quarkusio/quarkus/issues/45525">Github issue #45525</a>.
*/
public class RegisterServicesForReflectionFeature implements Feature {

@Override
public String getDescription() {
return "Makes methods of reachable hibernate services accessible through getMethods()`";
}

// The {@code duringAnalysis} method is invoked multiple times and increases the set of reachable types, thus we
// need to invoke {@link DuringAnalysisAccess#requireAnalysisIteration()} each time we register new methods.
private static final int ANTICIPATED_SERVICES = 100;
private static final Set<Class<?>> registeredClasses = new HashSet<>(ANTICIPATED_SERVICES);

@Override
public void duringAnalysis(DuringAnalysisAccess access) {
for (Class<?> service : access.reachableSubtypes(org.hibernate.service.Service.class)) {
if (registeredClasses.add(service)) {
RuntimeReflection.registerAllMethods(service);
access.requireAnalysisIteration();
}
}
}
}
Loading