Description

After I to compile native image from my test project that saves notes to MySql, it fails to start on missing NoSuchMethodException

Caused by: java.lang.NoSuchMethodException: org.hibernate.id.IdentityGenerator.<init>()
  at java.lang.Class.getConstructor0(DynamicHub.java:3585) ~[native-demo:na]
  at java.lang.Class.newInstance(DynamicHub.java:626) ~[native-demo:na]
  ... 39 common frames omitted

To work around the issue I register a hint myself:

public class NativeDemoHintsRegistrar implements RuntimeHintsRegistrar {

    @Override
    public void registerHints(RuntimeHints hints, ClassLoader classLoader) {

        hints.reflection().registerType(org.hibernate.id.IdentityGenerator.class,
            MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
    }
}

Considering that the goal of the spring native project is "to support your Spring applications, almost unmodified" I believe this missing hint is a bug.

Versions

Java

openjdk version "17.0.3" 2022-04-19
OpenJDK Runtime Environment GraalVM CE 22.1.0 (build 17.0.3+7-jvmci-22.1-b06)
OpenJDK 64-Bit Server VM GraalVM CE 22.1.0 (build 17.0.3+7-jvmci-22.1-b06, mixed mode, sharing)

Maven dependencies

spring-boot-starter-parent:3.0.0-M5
mysql-connector-java:8.0.30

Comment From: snicoll

Considering that the goal of the spring native project is "to support your Spring applications, almost unmodified" I believe this missing hint is a bug.

That isn't an accurate assumption I am afraid. We take care of hints we can infer but we can't support all the libraries out there. Hints for third party metadata are handled in a centralized repository.

@christophstrobl any opinion?

Comment From: christophstrobl

The hint does not show up in the hibernate-core metadata. @polarfish can you share the demo app you've been referring to in the description. I'm curious what triggers the hint. Maybe you've got the time to craft a PR for the metadata repo.

Comment From: polarfish

This is my project https://github.com/polarfish/spring-native-demo

I assume the problem has already been fixed in this PR https://github.com/oracle/graalvm-reachability-metadata/pull/72 which is included into reachability metadata 0.2.2

And I see from the build log of my application using graalvm-reachability-metadata-0.2.0:

[INFO] Downloaded GraalVM reachability metadata repository from https://github.com/oracle/graalvm-reachability-metadata/releases/download/0.2.0/graalvm-reachability-metadata-0.2.0.zip

Comment From: polarfish

@christophstrobl How can I update the version to graalvm-reachability-metadata to test the fix with the latest version (0.2.3)? (I do not see it in maven dependencies)

Comment From: snicoll

Please review the documentation.

Comment From: polarfish

I just tried to update the version of graalvm-reachability-metadata to the latest available version (0.2.3) and now it is working without the custom RuntimeHintsRegistrar. Thanks @snicoll