Search code examples
postgresqlspring-mvcmybatisdbunit

Can not using foreign table in DBunit


My project is using SpringMVC, MyBatis, and PostgreSql.

In postgres, I have 2 servers: sv1, sv2.

I imported a table from sv2 into sv1 using:

import foreign schema public limit to (tbl2) from server sv2 into public;

But, when using DBUnit to do testing, I cannot insert data into the foreign table tbl2. The exception is:

ERROR org.dbunit.database.DatabaseDataSet - Table 'tbl2' not found in tableMap=org.dbunit.dataset.OrderedTableNameMap

How can I use foreign table in DBUnit?


Solution

  • You need to configure the DatabaseConfig.

    databaseConfig.setProperty(PROPERTY_TABLE_TYPE, [array of string with table types]);
    or
    databaseConfig.setTableType([array with table types]);
    or configure your bean and add property

    <property name="tableType">
      <array value-type="java.lang.String">
      <value>TABLE</value>
      <value>FOREIGN TABLE</value>
     </array>
    </property>
    

    You can see the whole map of table types if you go to any of the implementations DatabaseMetadata and look for "TABLE".