Tuesday, January 24, 2017

Migrating from Hibernate 4 to 5

We have an application built on hibernate 4 and recently as part of application revamp we migrated to hibernate 5. During the migration, we noticed that the below run time error occurs when we try to store a record into the database.


java.sql.SQLSyntaxErrorException: Table 'hibernate_sequence' doesn't exist

This is a strange error for us as the application compiles, container starts with out any warnings and we can also retrieve records with out any errors.

To resolve this error, we need to add the below property to either the hibernate.properties file or persistence.xml file.

For hibernate.properties file, do this.
<prop key="hibernate.id.new_generator_mappings">false</prop>

For persistence.xml file do this
<property name="hibernate.id.new_generator_mappings" value="false"></property>