java - hibernate_sequence 创建重复键 'PRIMARY'
问题描述
以前工作的 Spring-Boot 应用程序出现了一个错误。它最后一次工作 100%。我对代码进行了零更改。似乎在 hibernate_sequence 表上输入了重复的主键。
今天和我的导师开发人员一起工作了三个小时。我们都难住了。我们尝试使用不同的数据库、重命名并启动应用程序的备份。尝试了不同的方法在实体上生成 id。我们将 Spring-Boot 更新为最新版本。每次我们删除/删除 hibernate_sequence 表时,您可以在控制台中看到它是在初始应用程序启动时生成的,您会得到Hibernate: insert into hibernate_sequence values (1)
两次。在这一点上,由于代码没有改变并且上周三运行良好,我的导师觉得这可能是我们不知道的地方的更新?
工作代码的 Github Repo:https ://github.com/chrisyoung0101/DrinkWithWineApp
IMG 1:生成 hibernate_sequence 之前的数据库/IMG 2:应用程序启动时的控制台/IMG 3:生成 hibernate_sequence 之前的数据库
尝试保存到 MySQL 中的配对表后出现错误:
2019-05-19 18:33:23.698 WARN 4405 --- [nio-8080-exec-7] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 1062, SQLState: 23000
2019-05-19 18:33:23.698 ERROR 4405 --- [nio-8080-exec-7] o.h.engine.jdbc.spi.SqlExceptionHelper : Duplicate entry '1' for key 'PRIMARY'
2019-05-19 18:33:23.702 ERROR 4405 --- [nio-8080-exec-7] o.h.i.ExceptionMapperStandardImpl : HHH000346: Error during managed flush [org.hibernate.exception.ConstraintViolationException: could not execute statement]
2019-05-19 18:33:23.717 ERROR 4405 --- [nio-8080-exec-7] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [PRIMARY]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement] with root cause
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '1' for key 'PRIMARY'
解决方案
推荐阅读
- spring - 什么是属性 management.health.redis.enabled 以及如何使用它?
- c# - 如何在 c# 函数中声明参数以使用 oracle db 获取输入输出?
- ios - Xamarin iOS:找不到 iPad mini 的模拟器,也没有最新的 iOS 版本 11.4.1
- swift - POD 安装问题:“`ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES”
- nginx - 使用 nginx 代理 S3 请求以进行授权
- reactjs - fetch api 或 whatwg-fetch 是否修改状态码为 304 到 200 的响应?
- python - 如何使用 pandas DataFrame 计算列表的字典?
- mysql - 在计算时间间隔时,有没有办法不改变 varchar 的类型?
- php - 从页面 A 在页面 B 上回显一个变量而不包含
- react-native - React native - 显示启动视频的最佳方式