Spring Boot MySQL : Table ‘DB_NAME.hibernate_sequence’ doesn’t exist

Spring Boot + Spring Data JPA + MySQL, and hits the following error message when the application starts :

Tested with :

  • Spring Boot 2.1.2.RELEASE
  • mysql-connector-java 8.0.13
  • Hibernate 5.3.7

java.sql.SQLSyntaxErrorException: Table 'DB_NAME.hibernate_sequence' doesn't exist
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
	at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:974)
	at com.mysql.cj.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:1024)
	at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
	at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
	at org.hibernate.id.enhanced.TableStructure.executeQuery(TableStructure.java:216)
	at org.hibernate.id.enhanced.TableStructure.access$300(TableStructure.java:46)
application.properties

spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=mkyong
spring.datasource.password=password

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Book {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String name;

Solution

By default, Hibernate generates key from hibernate_sequence table, we can disable it by setting this hibernate.use-new-id-generator-mappings to false.

application.properties

spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=mkyong
spring.datasource.password=password

spring.jpa.hibernate.use-new-id-generator-mappings=false

References

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

avatar