一个先前运行的Spring-Boot应用程序出现了一个错误。最后工作了100%。我对代码进行了零更改。似乎在hibernate_sequence表上输入了重复的主键。
今天与导师开发人员一起工作了三个小时。我们都陷入了困境。我们尝试使用其他数据库,重命名并启动该应用程序的备份。尝试了不同的方法来在实体上生成ID。我们将Spring-Boot更新为最新版本。每次我们删除/删除hibernate_sequence表时,您都可以在控制台中看到在初始应用程序启动时生成该表的时间,您会两次获得Hibernate: insert into hibernate_sequence values (1)
。此时,由于代码未更改,并且上周三工作正常,我的导师觉得这可能是我们不知道的地方的更新?
Github工作代码仓库: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'