DBUnit@Oracle DB時のAmbiguousTableNameException

これまたオールドスクールなツールを使っていて問題発生。
DBUnitを使って単体テストを実施していた時なのだけど、下記の例外に遭遇。

org.dbunit.database.AmbiguousTableNameException: AQ$_SCHEDULES
 at org.dbunit.database.DatabaseDataSet.initialize(DatabaseDataSet.java:140)
 at org.dbunit.database.DatabaseDataSet.getTableMetaData(DatabaseDataSet.java:186)
 at org.dbunit.operation.DeleteAllOperation.execute(DeleteAllOperation.java:98)
 at org.dbunit.operation.CompositeOperation.execute(CompositeOperation.java:67)

どうやらOracleを使っていて違うschemaに同じtable名が存在するとこうなっていて、
この時はコネクション生成するときにschemaを指定すべしとのこと。

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).

Another common reason for this exception to be thrown is when an XML file contains the same table multiple times whereas a different table is between the definition of the duplicate table.

2の案ね。

どうでも良いけどDBUnit.orgの本家サイトがドメイン切れて税理士紹介サイトに取られてる

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.