Mybatis报错Clock moved backwards. Refusing to generate id for xxx milliseconds


一、问题描述

启动服务报错:

Caused by: org.apache.ibatis.exceptions.PersistenceException:
### Error updating database.  Cause: java.lang.RuntimeException: Clock moved backwards.  Refusing to generate id for 27389059 milliseconds
### The error may exist in cn/lili/modules/file/mapper/FileMapper.java (best guess)
### The error may involve cn.lili.modules.file.mapper.FileMapper.insert
### The error occurred while executing an update
### Cause: java.lang.RuntimeException: Clock moved backwards.  Refusing to generate id for 27389059 milliseconds
        at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:196)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:181)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:427)
        ... 107 common frames omitted

二、解决方法

由于重启了服务器,导致系统时间倒退造成。
Mybatis 默认的 id 生成算法是雪花算法,时间倒退导致生成 id 抛异常。
解决方法是将系统时间修改为正确时间后,重启项目。

猜你喜欢

转载自blog.csdn.net/u012069313/article/details/125291959