Skip to content

Commit

Permalink
Register JPA static metamodel classes for reflection
Browse files Browse the repository at this point in the history
So that Hibernate ORM can populate their class_ attribute.

Alternatively we could have prevented Hibernate ORM from populating the
class_ attribute, but this would have been a breaking change in JVM
mode or for applications that already enabled reflection on the static
metamodel. This is safer.

I'm not adding a test because another pending PR is going to tighten up
native compilation checks, and those would fail if this PR doesn't work,
so we'll know.
  • Loading branch information
yrodiere committed Jan 10, 2025
1 parent f040b40 commit dae62d2
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public JpaModelBuildItem discoverModelAndRegisterForReflection() throws BuildExc
managedClassNames.addAll(collector.modelTypes);
for (String className : managedClassNames) {
reflectiveClass.produce(ReflectiveClassBuildItem.builder(className).methods().fields().build());
// Register static metamodel classes as well, so that their `class_` attribute can be populated.
// See org.hibernate.metamodel.internal.MetadataContext.populateStaticMetamodel
// Note: registering classes that do not exist is not a problem -- and is necessary if the application
// tries to access these classes via reflection anyway (which it will, through Hibernate ORM).
reflectiveClass.produce(ReflectiveClassBuildItem.builder(className + "_").fields().build());
}

if (!collector.enumTypes.isEmpty()) {
Expand Down

0 comments on commit dae62d2

Please sign in to comment.