记录使用springboot jpa的一次异常(java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä')

本文解决MySQL连接驱动更新、时区配置及Hibernate实体类注解缺失导致的问题,包括驱动类名更改、时区参数设置及@Entity和@Id注解使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.控制台会输出以下标红的信息

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

解决办法

可以根据提示把连接驱动类com.mysql.jdbc.Driver改为com.mysql.cj.jdbc.Driver,当然不做更改也不会报错

2.会出现以下异常信息

java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.

解决办法

作为数据库驱动的url后的第一个加上serverTimezone=UTC参数

jdbc:mysql://localhost:3306/growproject?serverTimezone=UTC&useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&useSSL=false

3.如果还出现类似以下的异常

org.hibernate.AnnotationException: No identifier specified for entity: com.example.growproject.domain.MenuEntity

1)出现原因,实体类中缺少@Id注解在这里插入图片描述
2)解决办法,为实体类的相关主键加上@Id即可

4.参考文章:

org.hibernate.AnnotationException: No identifier specified for entity:
java.sql.SQLException: The server time zone value ‘Öйú±ê׼ʱ¼ä’

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值