micronaut-sql
micronaut-sql copied to clipboard
JPA App working on JVM fails with "org.hibernate.AnnotationException" when running native
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
- run
./gradlew dockerBuild - run 'docker run demo:latest' => should work
- run
./gradlew dockerBuildNative - 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
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.
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.