0

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.

Martin Ahrer
  • 937
  • 3
  • 15
  • 28

3 Answers3

0

Try to replace the ID using something similar to this:

@Id
@Override
public UUID getId() {
    return super.getId();
}
  • Thanks, but I suspect that this is a bug in the native support. So I think this is just another hack like my attempt of copying the base class to my codebase. – Martin Ahrer Dec 19 '22 at 10:44
0

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

Martin Ahrer
  • 937
  • 3
  • 15
  • 28
0

Use the import of Javax / Jakarta for ID if you are using it for the spring framework it will give the same error.

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Entity
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Department {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long departmentID;
    private String deptartmentName;
    private String deptartmentAdress;
    private String departmentCode;
}