Oracle + dbunit gets AmbiguousTableNameException

dbunit dataset
dbunit databaseconfig

I am using dbunit to create database backups, which can be imported and exported. My application can use several database engines: MySQL, PostgreSQL, SQLServer, H2 and Oracle.

All of the above work fine with the following code:

            // Connect to the database 
        conn =BackupManager.getInstance().getConnection();
        IDatabaseConnection connection = new DatabaseConnection(conn);
        InputSource xmlSource = new InputSource(new FileInputStream(new File(nameXML)));
        FlatXmlProducer flatXmlProducer = new FlatXmlProducer(xmlSource);
        flatXmlProducer.setColumnSensing(true);

        DatabaseOperation.CLEAN_INSERT.execute(connection,new FlatXmlDataSet(flatXmlProducer));  

But on Oracle I get this exception:

!ENTRY es.giro.girlabel.backup 1 0 2012-04-11 11:51:40.542
!MESSAGE Start import backup
org.dbunit.database.AmbiguousTableNameException: AQ$_SCHEDULES
    at org.dbunit.dataset.OrderedTableNameMap.add(OrderedTableNameMap.java:198)
    at org.dbunit.database.DatabaseDataSet.initialize(DatabaseDataSet.java:231)
    at org.dbunit.database.DatabaseDataSet.getTableMetaData(DatabaseDataSet.java:281)
    at org.dbunit.operation.DeleteAllOperation.execute(DeleteAllOperation.java:109)
    at org.dbunit.operation.CompositeOperation.execute(CompositeOperation.java:79)
    at es.giro.girlabel.backup.ImportBackup.createData(ImportBackup.java:39)
    at es.giro.girlabel.backup.handlers.Import.execute(Import.java:45)

From the docs:

public class AmbiguousTableNameException extends DataSetException

This exception is thrown by IDataSet when multiple tables having the same name are accessible. This usually occurs when the database connection have access to multiple schemas containing identical table names.

Possible solutions:

1) Use a database connection credential that has access to only one database schema.

2) Specify a schema name to the DatabaseConnection or DatabaseDataSourceConnection constructor.

3) Enable the qualified table name support (see How-to documentation).

Frequently Asked Questions, My database is Oracle, and all >my tables are just one named ttt. AmbiguousTableNameException: COUNTRIES >at org.dbunit.database. is specified and that DbUnit detect that it is getting columns information from multiple tables having  #234 Oracle 10g and AmbiguousTableNameException Status: closed-invalid. Owner: matthias g When DbUnit is checking for ambiguous table name, it first uppercases

For whom uses SpringDBUnit. I had struggled with this very annoying issue. I had ended up solving the issue by adding the configuration for com.github.springtestdbunit.bean.DatabaseConfigBean and com.github.springtestdbunit.bean.DatabaseDataSourceConnectionFactoryBean.

This is my full spring context for SpringDBUnit

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
        <property name="url" value="jdbc:oracle:thin:@localhost:1521/XE" />
        <property name="username" value="xxxx" />
        <property name="password" value="xxxx" />
    </bean>


    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource">
            <ref bean="dataSource" />
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
            </props>
        </property>
        <property name="annotatedClasses">
            <list>
                <value>xxx.example.domain.Person</value>
            </list>
        </property>
    </bean>

    <bean id="dbUnitDatabaseConfig" class="com.github.springtestdbunit.bean.DatabaseConfigBean">
        <property name="skipOracleRecyclebinTables" value="true" />
        <property name="qualifiedTableNames" value="true" />
        <!-- <property name="caseSensitiveTableNames" value="true"/> -->
    </bean>
    <bean id="dbUnitDatabaseConnection"
        class="com.github.springtestdbunit.bean.DatabaseDataSourceConnectionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="databaseConfig" ref="dbUnitDatabaseConfig" />
        <property name="schema" value="<your_schema_name>"/>
    </bean>

a org.dbunit.database.AmbiguousTableNameException, We are getting AmbiguousTableNameException after migrating to Oracle 10g. The tests are working fine with Oracle 8i and 9i. We tried  Subject: [dbunit-user] org.dbunit.database.AmbiguousTableNameException (Ihave set schema name and also tried qualifiedTableNames andenabling skipOracleRecylceBins I am using Oracle 10g and DbUnit 2.2 (using ojdbc14.jar) This works fine on my PC but fails on our UNIX CI machine with: org.dbunit.database.AmbiguousTableNameException: CAPLAC_CI.BIN

Setting the database schema fixed it for me:

@Bean
public DatabaseDataSourceConnectionFactoryBean dbUnitDatabaseConnection(final DataSource dataSource){
    final DatabaseDataSourceConnectionFactoryBean connectionFactory = new DatabaseDataSourceConnectionFactoryBean();
    connectionFactory.setDataSource(dataSource);
    connectionFactory.setSchema(DB_SCHEMA);
    return connectionFactory;
}

dbUnit / Bugs / #154 AmbiguousTableNameException with Oracle , foldunfold. Table of Contents. How to get DBUnit to see aliases. Why am I (still) getting an "AmbiguousTableNameException"? In oracle org.dbunit.database. I'm just in the process of attempting to migrate to an Oracle schema, but am hitting this AmbiguousTableNameException problem too. Working with one of our DBAs we've cut down the privilages of the user to a minimum but I'm still getting this exception.

I had the same AmbiguousTableNameException while executing Dbunits aginst Oracle DB. It was working fine and started throwing error one day.

Rootcause: while calling a stored procedure, it got modified by mistake to lower case. When changed to upper case it stared working.

I could solve this also by setting the shema name to IDatabaseTester like iDatabaseTester.setSchema("SCHEMANAMEINCAPS")

Also please make sure your connection doesn't access only to many schemas having same table name.

DbUnit FAQ, Our Oracle database has multiple schemas with the same set of tables. When test​. final String schema = dbUnitConfigurationInstance.get(). DBUnit handles table names case-insensitively and gets confused. This can happen on database systems that are case-sensitive for identifiers, e.g. MySQL and (possibly) Microsoft SQL Server. This problem can only be solved by removing or renaming one of the offending tables.

AmbiguousTableNameException when multiple schem |JBoss.org , Hi all, I have problem with loading metadata for all database schema I am getting exception AmbiguousTableNameException. I have Oracle  Re: [dbunit-user] org.dbunit.database.AmbiguousTableNameException (I have set schema name and also tried un Re: [dbunit-user] org.dbunit.database.AmbiguousTableNameException (I have set schema name and also tried un

Users - oracle schema with multiple tables, Oracle + dbunit throws AmbiguousTableNameException - database. The table that gives me problems is defined in 3 schemas and I don't have the  Bugs item #1773564, was opened at 2007-08-13 23:13 Message generated for change (Comment added) made by rlogiacco You can respond by visiting: https://sourceforge.net

Oracle + dbunit throws AmbiguousTableNameException, Additional refinements for Oracle SDO_GEOMETRY datatype Fixes 2875253. Thanks to MySQL AmbiguousTableNameException incorrectly thrown Fixes 2489228. Thanks to MetaData get() are Pattern-Like Fixes 1644650. Thanks to​  Oracle + dbunit throws AmbiguousTableNameException. I'm using DBUnit to populate the database so that its content is a known content during testing. The db schema I'm working on is in an Oracle 11g instance in which they reside other db schemas.

Changes,

Comments
  • Thanks, I already solved this issue, but it was by the solution 1 you mentioned.
  • I you are using spring-dbunit, solution 1) can be achieved by setting the system property spring.dbunit.schema.
  • I got it fixed by setting DatabaseConfigBean#setQualifiedTableNames to true.