Skip to content

Missing reflection hint for AbstractPersistable #2735

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

Closed
christophstrobl opened this issue Dec 21, 2022 · 0 comments
Closed

Missing reflection hint for AbstractPersistable #2735

christophstrobl opened this issue Dec 21, 2022 · 0 comments
Assignees
Labels
theme: aot type: enhancement A general enhancement

Comments

@christophstrobl
Copy link
Member

christophstrobl commented Dec 21, 2022

AbstractPersistable defines a protected setter for the id property which will by default be omitted by the framework support only considering public methods. This results in the following reflection configuration

{
    "name": "org.springframework.data.jpa.domain.AbstractPersistable",
    "methods": [
      {
        "name": "isNew",
        "parameterTypes": [ ]
      },
      {
        "name": "getId",
        "parameterTypes": [ ]
      }
    ]
  },

Also the @Id annotation is present directly on the id property which would in turn not get registered if the field does not show up in the reflection config. Because of all this the JPA mapping for the id property does not work as expected preventing application start.

Caused by: org.hibernate.AnnotationException: Entity '...' has no identifier (every '@Entity' class must declare or inherit at least one '@Id' or '@EmbeddedId' property)

Till the issue is solved one may use RuntimeHintsRegistrar providing the required hints as outlined below.

@SpringBootApplication
@ImportRuntimeHints(ApplicationHints.class)
public class Application {

    // ...

    static class ApplicationHints implements RuntimeHintsRegistrar {
        public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
            hints.reflection().registerType(AbstractPersistable.class, DECLARED_FIELDS, INVOKE_DECLARED_METHODS);
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: aot type: enhancement A general enhancement
Projects
None yet
2 participants