I'm experimenting with DBUnit (2.6.0) and I'm trying to export my full database (PostgreSQL). However the following exception is thrown:
Exception in thread "main" org.dbunit.database.AmbiguousTableNameException: FLYWAY_SCHEMA_HISTORY
This is correct behaviour since I have two tables in different schemas with the same name:
I then read that you can set a property Qualified Table Names (http://dbunit.sourceforge.net/properties.html#qualifiedtablenames) that will take into account the schema name. So my code now is the following:
public class DbUnitExportTool {
public static void main(String[] args) throws Exception {
// database connection
Class.forName("org.postgresql.Driver");
Connection jdbcConnection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/*******", "********", "********");
IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);
connection.getConfig().setProperty(DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES, true);
exportDatabase(connection);
}
private static void exportDatabase(IDatabaseConnection connection) throws Exception {
// full database export
IDataSet fullDataSet = connection.createDataSet();
FlatXmlDataSet.write(fullDataSet, new FileOutputStream("full.xml"));
}
}
The problem is that I still get the same error and I don't know why since it should be resolved by setting the qualified table names to true? Does anybody know what I'm doing wrong?
The problem was the JDBC driver has a faulty comparison in method: haveMinimumServerVersion(String ver) (link to bug). I solved this by using an exclusion in my maven dependencies:
<dependency>
<groupId>org.dbunit</groupId>
<artifactId>dbunit</artifactId>
<version>2.6.0</version>
<exclusions>
<exclusion>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
</exclusion>
</exclusions>
</dependency>
This solved my problem. I hope it can help somebody else.