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

New org.hibernate.orm Hibernate Core 6.2.0.Final Hints Break Native Image #273

Closed
matthenry87 opened this issue Apr 21, 2023 · 17 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@matthenry87
Copy link

matthenry87 commented Apr 21, 2023

Describe the bug
My Spring Boot 3 native image apps no longer launch. Hints that are present in the previous org.hibernate.orm Hibernate Core version are missing from the new one.

To Reproduce
Steps to reproduce the behavior:

Attempt to launch a Spring Boot 3 native image app that uses Hibernate Core 6.2.0.Final

Expected behavior
App launches like prior to release of new hints.

Logs

[INFO] [graalvm reachability metadata repository for org.hibernate.orm:hibernate-core:6.1.7.Final]: Configuration directory is org.hibernate.orm/hibernate-core/6.2.0.Final

System Info (please complete the following information):

  • OS: Kubernetes 1.25, containerd, debian-based builder pod
  • GraalVM Version latest
  • Java Version 17
  • Plugin version latest Spring Boot managed version in 3.0.6

Additional context
So far had to add:

            hints.reflection()
                    .registerType(NoJtaPlatform.class, INTROSPECT_PUBLIC_METHODS)
                    .registerConstructor(NoJtaPlatform.class.getConstructor(), INVOKE)

                    .registerConstructor(SpringImplicitNamingStrategy.class.getConstructor(), INVOKE)
                    .registerConstructor(CamelCaseToUnderscoresNamingStrategy.class.getConstructor(), INVOKE);

and now:

... 27 common frames omitted\nCaused by: java.lang.ClassNotFoundException: org.hibernate.cfg.beanvalidation.TypeSafeActivator
at java.base@17.0.6/java.lang.Class.forName(DynamicHub.java:1132)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:120)
... 28 common frames omitted\n
@matthenry87 matthenry87 added the bug Something isn't working label Apr 21, 2023
@matthenry87 matthenry87 changed the title New Hibernate Core 6.2.0.Final Hints Break Native Image New org.hibernate.orm Hibernate Core 6.2.0.Final Hints Break Native Image Apr 21, 2023
@matthenry87
Copy link
Author

App does build when reverting to prior hints:

<plugin>
    <groupId>org.graalvm.buildtools</groupId>
    <artifactId>native-maven-plugin</artifactId>
    <configuration>
        <metadataRepository>
            <dependencies>
                <dependency>
                    <groupId>org.hibernate.orm</groupId>
                    <artifactId>hibernate-core</artifactId>
                    <metadataVersion>6.1.1.Final</metadataVersion>
                </dependency>
            </dependencies>
        </metadataRepository>
    </configuration>
</plugin>

@msupic
Copy link
Contributor

msupic commented Apr 21, 2023

In Hibernate Core 6.2.0.Final, the org.hibernate.cfg.beanvalidation.TypeSafeActivator has been replaced withorg.hibernate.boot.beanvalidation.TypeSafeActivator so if you are using older version of hibernate, you need to use metadata for 6.1.1.Final

@matthenry87
Copy link
Author

There native plugin uses the latest version available by default. Spring Boot's latest version uses 6.1.7.Final, but since only 6.1.1.Final is available, it will grab the latest available version.

So now, a Spring Boot 3 app will fail to launch with the default configuration.

@matthenry87
Copy link
Author

Perhaps an enhancement could be made - so that it won't use the hints for a higher minor version.

@sdeleuze
Copy link
Collaborator

I think we are impacted by the issue I was describing in #62. We will discuss how to handle that and find a proper fix.

@ArnauAregall
Copy link

ArnauAregall commented May 14, 2023

I believe the work done in #274 was not enough as seems the following classes from Hibernate core are still not reachable.

  • org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform
  • org.hibernate.service.jta.platform.internal.NoJtaPlatform

Those are used by Spring Boot Hibernate JPA auto-configuration:

https://github.com/spring-projects/spring-boot/blob/02b5e80f7a3e3794cc4ec035e29a41f730b1418b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.java#L72-L78

Running a native Spring Boot application using metadata 0.9.22 (from NBT 0.3.0) still fails as those classes cannot be found.

	private Object getNoJtaPlatformManager() {
		for (String candidate : NO_JTA_PLATFORM_CLASSES) {
			try {
				return Class.forName(candidate).getDeclaredConstructor().newInstance();
			}
			catch (Exception ex) {
				// Continue searching
			}
		}
		throw new IllegalStateException(
				"No available JtaPlatform candidates amongst " + Arrays.toString(NO_JTA_PLATFORM_CLASSES));
	}

@matthenry87
Copy link
Author

matthenry87 commented May 14, 2023

I believe the work done in #274 was not enough as seems the following classes from Hibernate core are still not reachable.

  • org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform
  • org.hibernate.service.jta.platform.internal.NoJtaPlatform

Those are used by Spring Boot Hibernate JPA auto-configuration:

https://github.com/spring-projects/spring-boot/blob/02b5e80f7a3e3794cc4ec035e29a41f730b1418b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.java#L72-L78

Running a native Spring Boot application using metadata 0.9.22 (from NBT 0.3.0) still fails as those classes cannot be found.

	private Object getNoJtaPlatformManager() {
		for (String candidate : NO_JTA_PLATFORM_CLASSES) {
			try {
				return Class.forName(candidate).getDeclaredConstructor().newInstance();
			}
			catch (Exception ex) {
				// Continue searching
			}
		}
		throw new IllegalStateException(
				"No available JtaPlatform candidates amongst " + Arrays.toString(NO_JTA_PLATFORM_CLASSES));
	}

I don't believe the work done in the PR you linked was meant to fix this. Sébastien from the Spring team is working on a fix: #62

@ArnauAregall
Copy link

I don't believe the work done in the PR you linked was meant to fix this. Sébastien from the Spring team is working on a fix: #62

@matthenry87 My bad, I now realized what's happening in your case (if I got it right, your metadata is resolved from 6.2.0.Final instead of the one compatible with the 6.1.x version you are using).

Probably different case although latest one provided by Spring Boot (3.1.0-RC2) is now 6.2.2.Final which should resolve to latest metadata (6.2.0.Final) and issues are still around.

@sdeleuze
Copy link
Collaborator

I confirm the issue with Spring Boot 3.1.0-RC2, but looks like a different one where some metadata are missing from Hibernate 6.2 hints.

@sdeleuze sdeleuze modified the milestones: 0.3.0, 0.3.1 May 15, 2023
@sdeleuze
Copy link
Collaborator

@ArnauAregall Can you please create a dedicated issue for the Hibernate 6.2 breakage with Boot 3.1?

@sdeleuze sdeleuze removed this from the 0.3.0 milestone May 15, 2023
@sdeleuze
Copy link
Collaborator

@ArnauAregall Wait, looks like the issue may be on Spring Boot side, I will report that to them.

@ArnauAregall
Copy link

Thanks a lot @sdeleuze!

Let me know if I can help or support you somehow, even with a sample app showcasing the issue.

@sdeleuze
Copy link
Collaborator

sdeleuze commented May 15, 2023

@goafabric
Copy link

Hello lovely people, is there a suggested approach for Boot 3.1 final that just came out a few hour ago ?
As described above this comes with hibernat 6.2
And i tried native tools 0.9.20 / .21 /.22 .. all of them break

@wilkinsona
Copy link
Contributor

It's hard to say for certain as "all of them break" doesn't give us much to go on, but you may be hitting spring-projects/spring-framework#30492. You could try Framework 6.0.10-SNAPSHOT that's available from https://repo.spring.io/snapshot.

@goafabric
Copy link

goafabric commented May 19, 2023

@wilkinsona
thx for your fast reply.. i did not get to much into details
because the springs own aot-smoketests for data-jpa still break .. so i thought this is an ongoing issue ?

the error without postive the entire trace:

"Caused by: com.oracle.svm.core.jdk.UnsupportedFeatureError: No classes have been predefined during the image build to load from bytecodes at runtime."
Entire trace is here:
https://github.com/goafabric/person-service/actions/runs/5021852966/jobs/9004646245

So it could be related to the bytebuddy issue mentioned in your link.

So if the fix is in framework 6.0.10, i guess the fix will be available in boot 3.1.1 ?

@goafabric: remindme

@wilkinsona
Copy link
Contributor

Yes, that's the plan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants