1

I have entity with field id annotated by @Id:

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

@Entity
@Table(name = "orders")
@Data
@SuperBuilder
@NoArgsConstructor
public class Order {

  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Long id;
}

Everything works properly when I run application with mvn mn:run. But if build app with mvn package -Dpackaging=native-image and then run built app I've received an error:

org.hibernate.AnnotationException: No identifier specified for entity: Order

micronaut version: 2.3.4, micronaut data version: 2.2.4

TOUDIdel
  • 1,322
  • 14
  • 22

2 Answers2

0

try to add path to the pom.xml

<path>
   <groupId>io.micronaut</groupId>
   <artifactId>micronaut-graal</artifactId>
   <version>${micronaut.version}</version>
</path>

when adding lombok

0

I had the same problem when building my Application as a Native-image.

I solved this doing two things:

  1. Making the id field public (and not private)
@Id
public Long id;
  1. Adding to the pom.xml the Annotation Processor for the GraalVM to build Native-image with reflection (as specified in Micronaut Docs)
    • So add this to pom.xml
 <annotationProcessorPaths> 
  ...
    <path>
      <groupId>io.micronaut</groupId>
      <artifactId>micronaut-graal</artifactId>
      <version>3.7.4</version>
    </path>
  ... 
 </annotationProcessorPaths>

NOTE:

  • Be sure that is not missing the @Id annotation on id field
  • Be sure that the @Id annotation is imported with:
import javax.persistence.Id;
Luca
  • 51
  • 2