Main Tutorials

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 Author

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

Comments

Subscribe
Notify of
6 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Jeet Singh Parmar
4 years ago

Instead of setting this property to false
spring.jpa.hibernate.use-new-id-generator-mappings=false

We can add below property then also it will work
spring.jpa.hibernate.ddl-auto=update

Tanzeel
1 year ago

Thanks alot, the mentioned solution did not work for me, but your solution has worked.

Raj
4 years ago

Yes

Raccoon
4 years ago

Why do we get this error?
And this solution doesn’t work for me
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

CREATE TABLE model
(
id SERIAL NOT NULL,
name VARCHAR(64) NOT NULL UNIQUE,
PRIMARY KEY (id)
);

sagar
4 years ago

this solution works

jeyaraj
1 year ago

This Solution is working