启动报错如下图所示:

 

解决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

相关文章:

  • 2022-12-23
  • 2021-11-24
  • 2022-12-23
  • 2022-02-08
  • 2021-04-28
  • 2022-01-17
猜你喜欢
  • 2022-01-17
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2022-02-11
  • 2022-12-23
  • 2021-10-22
相关资源
相似解决方案