jaygajera17 / E-commerce-project-springBoot

This project serves as an easy-to-understand setup for beginners , providing a base foundation in Spring Boot , MVC & hibernate.
https://jaygajera17.github.io/E-commerce-project-springBoot/
520 stars 512 forks source link

register met error "Duplicate entry '1' for key 'customer.PRIMARY' #41

Closed WangGithub0 closed 4 days ago

WangGithub0 commented 8 months ago

Caused by: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '1' for key 'customer.PRIMARY' at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:118) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:916) at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1061) at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1009) at com.mysql.cj.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:1320) at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:994) at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:197)

WangGithub0 commented 8 months ago

Because ran the basedata.sqlscript on the database has manually inserted records with IDs '1' and '2' into the CUSTOMER table. Since the code use the GenerationType.AUTO strategy for ID generation, MySQL is attempting to automatically generate the next available ID when try to insert a new record. However, this conflicts with the existing IDs manually inserted before.