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
Add native support for @Convert
on JPA entities
#29771
Comments
Thanks for the sample. Unfortunately, it doesn't compile:
|
@wilkinsona Sorry, I forgot to push the latest changes. It should compile now. |
Running the app with debug logging enabled shows that both
This is due to a lack of reflection hints which means that the converter class cannot be created reflectively in a native image. You could work around the problem by using |
@wilkinsona Thanks for the clarification. I will look in to |
As discussed with @sdeleuze, |
@NicklasWallgren Your sample app starts when this change is applied to its main class: diff --git a/src/main/java/com/example/demo/DemoApplication.java b/src/main/java/com/example/demo/DemoApplication.java
index 64b538a..76b9b00 100644
--- a/src/main/java/com/example/demo/DemoApplication.java
+++ b/src/main/java/com/example/demo/DemoApplication.java
@@ -1,13 +1,29 @@
package com.example.demo;
+import org.springframework.aot.hint.MemberCategory;
+import org.springframework.aot.hint.RuntimeHints;
+import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.ImportRuntimeHints;
+
+import com.example.demo.DemoApplication.ConverterRuntimeHints;
@SpringBootApplication
+@ImportRuntimeHints(ConverterRuntimeHints.class)
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
+ static class ConverterRuntimeHints implements RuntimeHintsRegistrar {
+
+ @Override
+ public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
+ hints.reflection().registerType(EmailConverter.class, MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS);
+ }
+
+ }
+
} |
@wilkinsona Great, thanks for the help! |
@Convert
on JPA entities
This commit infers the reflection hints required for converters when they are specified with the @convert annotation at class or field level. It also refines the hints generated for @converter in order to just generate the construct hint, not the public method one which should be not needed. Closes spring-projectsgh-29771
I've run into an issue with the
jakarta.persistence.Convert
annotation with GraalVM and Spring Native, see the stacktrace below.I'm a bit unsure if this issue should be reported here, with the Hibernate project or elsewhere .
The
Converter
is implemented as shown below and is applied via@Convert(converter = ....)
.The issue does not present itself if I remove the
@Convert
and instead auto apply it via@Converter(autoApply = true)
.You can reproduce the issue with https://github.com/NicklasWallgren/spring-boot-native-issue
The text was updated successfully, but these errors were encountered: