Skip to content

Hibernate tries to reflectively access metamodel classes not registered for reflection #45503

Closed
@zakkak

Description

Describe the bug

Hibernate seems to be reflectively accessing some metamodel classes that we don't register for reflection in native-mode.

The classes are accessed in https://github.com/hibernate/hibernate-orm/blob/9d52e3c9dfc49a9be804220c2382055d5901daa9/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java#L728-L731

Relates to #41995

Expected behavior

All reflective accesses should be registered.

Actual behavior

Reflective accesses are not registered resulting in warnings like the following when using -H:ThrowMissingRegistrationErrors=:

...
org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively access class

   io.quarkus.it.jpa.db2.Human_

without it being registered for runtime reflection. Add io.quarkus.it.jpa.db2.Human_ to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
  java.base@23.0.1/java.lang.Class.forName(DynamicHub.java:1475)
  io.quarkus.hibernate.orm.runtime.service.FlatClassLoaderService.classForName(FlatClassLoaderService.java:36)
  org.hibernate.metamodel.internal.MetadataContext.populateStaticMetamodel(MetadataContext.java:722)
  org.hibernate.metamodel.internal.MetadataContext.wrapUp(MetadataContext.java:395)
org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively access class

   io.quarkus.it.jpa.db2.Customer_

without it being registered for runtime reflection. Add io.quarkus.it.jpa.db2.Customer_ to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
  java.base@23.0.1/java.lang.Class.forName(DynamicHub.java:1475)
  io.quarkus.hibernate.orm.runtime.service.FlatClassLoaderService.classForName(FlatClassLoaderService.java:36)
  org.hibernate.metamodel.internal.MetadataContext.populateStaticMetamodel(MetadataContext.java:722)
  org.hibernate.metamodel.internal.MetadataContext.wrapUp(MetadataContext.java:345)
org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively access class

   io.quarkus.it.jpa.db2.Person_

without it being registered for runtime reflection. Add io.quarkus.it.jpa.db2.Person_ to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
  java.base@23.0.1/java.lang.Class.forName(DynamicHub.java:1475)
  io.quarkus.hibernate.orm.runtime.service.FlatClassLoaderService.classForName(FlatClassLoaderService.java:36)
  org.hibernate.metamodel.internal.MetadataContext.populateStaticMetamodel(MetadataContext.java:722)
  org.hibernate.metamodel.internal.MetadataContext.wrapUp(MetadataContext.java:345)
...

How to Reproduce?

./mvnw clean package -Dnative -Dnative.surefire.skip \
  -Dquarkus.native.builder-image=quay.io/quarkus/ubi-quarkus-mandrel-builder-image:jdk-23 \
  -pl integration-tests/jpa-db2/ \
  -Dquarkus.native.additional-build-args=-H:ThrowMissingRegistrationErrors=

./integration-tests/jpa-db2/target/quarkus-integration-test-jpa-db2-999-SNAPSHOT-runner -XX:MissingRegistrationReportingMode=Warn

Output of uname -a or ver

No response

Output of java -version

21.0.5

Mandrel or GraalVM version (if different from Java)

Mandrel-24.1.1.0-Final

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions