1

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]
Kamil Naja
  • 6,267
  • 6
  • 33
  • 47
Mihkel L.
  • 1,543
  • 1
  • 27
  • 42

1 Answers1

4

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>
Mihkel L.
  • 1,543
  • 1
  • 27
  • 42
bhdrk
  • 3,415
  • 26
  • 20
  • This gives: `[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]` – Mihkel L. Apr 22 '14 at 19:22
  • I removed `TABLE` and replaced it with `SEQUENCE` then it works.. but of course JDBC can't copy things :( – Mihkel L. Apr 22 '14 at 19:28