Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Table 'DBNAME.hibernate_sequence' doesn't exist

I have a SpringBoot 2.0.1.RELEASE application using spring data / jpa

<dependency>     <groupId>org.springframework.boot</groupId>     <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> 

But when I do an update in the Amazon Aurora DB, I got this error:

2018-04-13 09:20 [pool-1-thread-1] ERROR o.h.id.enhanced.TableStructure.execute(148) - could not read a hi value com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'elbar.hibernate_sequence' doesn't exist at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

I have this in the entity I want to save

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

I would like to avoid also any drawback in the DB to fetch the ID .

like image 243
en Peris Avatar asked Apr 13 '18 09:04

en Peris


People also ask

How to avoid hibernate_ sequence table?

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

What is hibernate_sequence table?

If you use strategy="AUTO" , Hibernate will generate a table called hibernate_sequence to provide the next number for the ID sequence. You may have forgotten to add the AutoIncrement feature to your table's PK.

Why hibernate_sequence is created?

hibernate_sequence' doesn't exist error occurs when the hibernate_sequence table does not exist in the database and auto id generation in hibernate is enabled. Hibernate generates and stores the current id for auto-increment column values in the hibernate sequence table. The error java. sql.


1 Answers

With the generation GenerationType.AUTO hibernate will look for the default hibernate_sequence table , so change generation to IDENTITY as below :

 @Id  @GeneratedValue(strategy = GenerationType.IDENTITY)  private Long id; 
like image 155
Spring Avatar answered Sep 18 '22 23:09

Spring