javahibernatemavensql-maven-plugin

Import problem "hibernate_sequence" table with Generation.type


So I'm trying to use a sql-maven-plugin to import my backup database. I used annotation @GeneratedValue(strategy = GenerationType.TABLE ) on my Entities, so my backup database has hibernate_sequence table with it.

How to avoid this error, but still use @Id @GeneratedValue ?

[ERROR] Failed to execute goal org.codehaus.mojo:sql-maven-plugin:1.5:execute (populate-database) on project app: ERROR: relation "hibernate_sequence" already exists -> [Help 1]

Solution

  • it is clear. hibernate_sequence already exists. your data is loaded already and you try to load data again. in this case, you can drop hibernate_sequence table or database for a fresh install.

      <execution>
        <id>create-db</id>
        <phase>process-test-resources</phase>
        <goals>
          <goal>execute</goal>
        </goals>
        <configuration>
          <url>jdbc:postgresql://localhost:5432:yourdb</url>
          <!-- no transaction -->
          <autocommit>true</autocommit>
          <sqlCommand>DROP SEQUENCE hibernate_sequence</sqlCommand>
        </configuration>
      </execution>