org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: cn.merson.redbirds.entity.Store
org.hibernate.AnnotationException: No identifier specified for entity: cn.merson.redbirds.entity.Store
今天在用Spring Boot整合spring-data-jpa时遇到如上的错误,其实这个报错本身很简单,究其原始是因为没有为标注为@Entity的实体类注明主键,当我准备去改错的时候,发现自己分明已经用@Id和@GenerateValue标注在ID上,怎么还会报错了,排查了半天,发现是导错包:import org.springframework.data.annotation.Id;这是Spring提供的;而应该导入javax.persistence.Id,很细微的差别,可能不注意看就错了而且很难去排查问题;
另外:org.springframework.data.annotation.Id和javax.persistence.Id接口声明都一样,
这是javax提供的: