简体   繁体   中英

id property inherited from AbstractPersistable is not recognized in a Spring Boot AOT compiled native image

I have migrated a Spring Boot application to Spring Boot 3 and compiled a native image. The application is exposing a simple entity using Spring Data REST (see code below).

During application startup it terminates with complaining that no identifier property has been detected.

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

So it looks like the mapping information of the base class providing the @Id annnotated id property has been lost.

After copying the code of AbstractPersistable to my code base and rebuilding the native image the application starts properly and works.

package at.martinahrer.cd.model;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.jpa.domain.AbstractPersistable;
import jakarta.persistence.Entity;

@Entity
@Getter
@Setter
public class Address extends AbstractPersistable<Long> {
    private String line1;
    private String line2;
    private String zip;
    private String city;
    private String state;
    private String country;
}

So is some more configuration required? I added the hibernate plugin as this is suggested by the wizards of start.spring.io.

Try to replace the ID using something similar to this:

@Id
@Override
public UUID getId() {
    return super.getId();
}

In fact it turned out that this is missing reflection configuration for the native support. I reported a bug which they posted to https://github.com/spring-projects/spring-data-jpa/issues/2735 along with a solution

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM