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

JPA App working on JVM fails with "org.hibernate.AnnotationException" when running native #716

Open
tmohme opened this issue Aug 12, 2022 · 2 comments

Comments

@tmohme
Copy link

tmohme commented Aug 12, 2022

Expected Behavior

The application should run native when built with "./gradlew clean dockerBuildNative" the same way as it runs when built with "./gradlew dockerBuild".

Actual Behaviour

When running the native application, I get a org.hibernate.AnnotationException: com.example.DemoClassId has no persistent id property: com.example.DemoClass.id

Steps To Reproduce

clone https://github.com/tmohme/mn-defect-demo, then

  1. run ./gradlew dockerBuild
  2. run 'docker run demo:latest' => should work
  3. run ./gradlew dockerBuildNative
  4. run 'docker run demo:latest' => fails with org.hibernate.AnnotationException: com.example.DemoClassId has no persistent id property: com.example.DemoClass.id

Environment Information

  • macOS 12.5, Intel CPU
  • OpenJDK 64-Bit Server VM Zulu11.56+19-CA (build 11.0.15+10-LTS, mixed mode)

Example Application

https://github.com/tmohme/mn-defect-demo

Version

3.6.0

@yawkat
Copy link
Member

yawkat commented Aug 15, 2022

libraries like hibernate won't just work out-of-the-box with native image. they need some reflection config.

from the error, it may be enough to simply add @ReflectiveAccess to the bean in question.

@tmohme
Copy link
Author

tmohme commented Aug 15, 2022

Thank you for your suggestion.
I'm aware that Hibernate makes heavy use of reflection.
Nevertheless I was under the assumption, that Micronaut already takes care of this . . . because Micronaut has dedicated support for Hibernate and - apart from @EmbeddedId - everything works fine in the native app.

Anyway, adding @ReflectiveAccess to the DemoClassId class was enough to solve the problem for me.

It looks like Micronaut somehow manages this (letting the Annotation survive native-compile) automatically for other JPA Annotations.
Maybe it would be worthwhile to extend this support to include @EmbeddedId.

@yawkat yawkat transferred this issue from micronaut-projects/micronaut-core Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants