Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate-sequence doesn't exist

I tried to upgrade hibernate from 4 to 5 in my project with spring 4.2 version. After this upgrade, I found the following error in my stack trace when I called a method for updating.

10:53:32,185 ERROR TableStructure:149 - could not read a hi value
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'test.hibernate_sequence' doesn't exist 

I changed the auto incremented Id with annotation

@GeneratedValue(strategy=GenerationType.AUTO) 

still the error remains.

like image 765
rParvathi Avatar asked Oct 06 '15 11:10

rParvathi


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 used for?

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.

What is hibernate ID New_generator_mappings?

Hibernate 3.5 introduced a core property named hibernate. id. new_generator_mappings that directs how identity or sequence columns are generated when using @GeneratedValue .


2 Answers

You can also put :

@GeneratedValue(strategy = GenerationType.IDENTITY)

And let the DateBase manage the incrementation of the primary key:

AUTO_INCREMENT PRIMARY KEY
like image 186
Kikou Avatar answered Nov 15 '22 23:11

Kikou


You need to set for Hibernate5.x <property name="hibernate.id.new_generator_mappings">false</property>.. see and link.

For older version of hibernate 4.x: <prop key="hibernate.id.new_generator_mappings">false</prop>

like image 40
rParvathi Avatar answered Nov 15 '22 23:11

rParvathi