SpringBoot JPA错误:Caused by: org.hibernate.AnnotationException: No identifier specified for entity

使用Spring JPA整合项目时,使用了注解 @Entity,项目启动时会提示以下错误:

Caused by: org.hibernate.AnnotationException: No identifier specified for entity

意思是,使用 @Entity 注解的类,需要指定唯一主键标识符字段。以下是示例:

  • 错误的示例:
@Entity  // 需要存在person表,且需要指定主键id
@Document  // 需要配置mongodb
public class Person {
}
  • 正确的配置:
@Entity  // 需要存在person表,且需要指定主键id
@Document  // 需要配置mongodb
public class Person {
    @Id
    @GeneratedValue
    private Long id;
}


posted @ 2018-10-02 11:32  IT当时语_青山师  阅读(54)  评论(0)    收藏  举报  来源