No identifier specified for entity: springboot-jpa报错No identifier specified for entity

时间:2023-03-08 22:50:05
No identifier specified for entity: springboot-jpa报错No identifier specified for entity

说明:此次学习使用了springboot框架,jpa注解映射实体类

1,No identifier specified for entity: com.tf.model.User

看到此错误第一反应百度谷歌。(经过一阵检索)看到了答案

原因:pojo实体bean缺少了主键

于是返回项目中查看实体类

 @Id

 @GeneratedValue(strategy= GenerationType.AUTO)

 private Long id;
  • 1
  • 2
  • 3
  • 4
  • 5

缺少主键?开玩笑奥,我都有!细心的我又看了看数据表中字段设置,还是没有任何问题!啊!天将降大任于斯人也!幸好我聪明伶俐,经过一番折腾(此处省略半天时间),终于发现了问题!


正文开始!

原因:包没有引对(类名相同,但不同的包有同一种类)

改正前(部分):

import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Id;
  • 1
  • 2
  • 3

改正后:

import javax.persistence.*;
  • 1

没错,这两个包中同时有@id,而持久话用到声明主键的@ID在javax.persistence.*中,如果两个包同时存在,正确的这个会被覆盖(至于为什么,sorry,I don’t know)

2,Establishing SSL connection without server’s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn’t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false’. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

这个是报出的一个警告! 
原因:在高版本mysql中需要指定是否进行SSL连接

解决方案:配置文件中在spring.datasource.url 加入选项useSSL=false/true

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.****.net/qq_33240946/article/details/52916532