1

所以我正在尝试使用 sql-maven-plugin 来导入我的备份数据库。我在我的实体上使用了注释@GeneratedValue(strategy = GenerationType.TABLE ),所以我的备份数据库有hibernate_sequence它的表。

如何避免这个错误,但仍然使用@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]
4

1 回答 1

4

很明显。hibernate_sequence 已经存在。您的数据已经加载,您尝试再次加载数据。在这种情况下,您可以删除 hibernate_sequence 表或数据库进行全新安装。

  <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>
于 2014-04-22T19:10:06.470 回答