ERROR: relation “hibernate_sequence” does not exist

Recently while working on a Spring Boot project, I grabbed a fresh copy of the source from our GIT repository. After importing the Maven project I attempted to run the test suite attached to the code base. The unit tests ran fine but as soon as it hit the portion of code responsible for testing the integration with the RDMBS, which is Postgresql, I was met with the following error:

org.postgresql.util.PSQLException: ERROR: relation “hibernate_sequence” does not exist

After a bit of investigation into the code that was attempting to run, it appeared that the issue was coming from an annotation. The following line attached to the Id was the culprit:

@GeneratedValue(strategy = GenerationType.AUTO)

After a little more digging, it became apparent that the database had initially been set up manually and this sequence had been generated during the creation of tables. When Hibernate was tasked with creating the tables in a fresh database, it couldn’t seem to find what it was looking for.

To resolve the issue, simply changing the annotation value got it returning the expected behaviour:

@GeneratedValue(strategy = GenerationType.IDENTITY)

While looking at this, it became apparent that we needed to start doing two things:

  1. Rely less on Hibernate to create the tables
  2. Perform the integration tests against multiple database vendors to verify that we have met our mandated condition to make the application vendor agnostic.

Ā References

  1. http://docs.oracle.com/javaee/6/api/javax/persistence/GenerationType.html

Leave a Reply

Your email address will not be published. Required fields are marked *