解决Entity 实体类中加了@Id 注解后仍然出现org.hibernate.AnnotationException: No identifier specified for entity 错误

启动报错如下图所示:

解决方案:

查看网上的资料,大部分都说在实体类中没有添加加主键的注解@Id,这个是必须的。但是我的实体类中明明已经添加了@Id,为什么还会报这个错误呢?

后来检查了很久,发现是我import的包出现了错误,正确的应该是import javax.persistence.Id 而我却导入了org.springframework.data.annotation.Id 这样虽然@Id 在IDE语法检查时不会报错,但并会使我编译错误起不来,因此运行时会报上面但错误。

参考文章:https://blog.csdn.net/qq_24082175/article/details/79084677

原文地址:https://www.cnblogs.com/longronglang/p/12031713.html