Oracle + dbunit引发AmbiguousTableNameException [英] Oracle + dbunit throws AmbiguousTableNameException

查看:61
本文介绍了Oracle + dbunit引发AmbiguousTableNameException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用DBUnit来填充数据库,以便其内容是测试期间的已知内容.

我正在处理的数据库模式是在Oracle 11g实例中,它们驻留在其他数据库模式中.在其中的某些模式中,已定义了一个表,该表已与公共同义词相关联,并且已被授予选择权.

当我运行定义数据库填充方式的xml时,如果xml文件包含在多个模式中定义的表,DBUnit也会在该表上抛出AmbiguousTableNameException异常./p>

我发现有3种解决方案来解决此问题:

  1. 使用仅可访问一个的数据库连接凭据数据库架构.
  2. 为数据库连接指定架构名称,或者DatabaseDataSourceConnection构造函数.
  3. 启用合格的表名支持(请参阅操作方法文档).

在我的情况下,我只能应用解决方案1,但是即使采用了解决方案1,我也会遇到相同的例外情况.

给我带来麻烦的表是在3种模式中定义的,我没有机会以任何方式对其进行操作.

请,有人可以帮助我吗?

解决方案

我找到了解决方案:我在表的名称中指定了架构,并将属性设置为 true http://www.dbunit.org/features/qualifiedTableNames (对应于 org.dbunit.database.FEATURE_QUALIFIED_TABLE_NAMES ).

通过这种方式,我用于填充表格的xml代码如下所示:

 <?xml version ='1.0'encoding ='UTF-8'?><数据集>< SCHEMA.TABLE ID_FIELD ="1"/></dataset> 

其中 SCHEMA 是架构名称, TABLE 是表名称.

要使用此属性,我使用了以下代码:

  DatabaseConfig dBConfig = dBConn.getConfig();//dBConn是一个IDatabaseConnectiondBConfig.setProperty(DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES,true); 

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. In some of these schemas has been defined a table to which has been associated with a public synonym and on which have been given the rights to select.

When I run the xml that defines how the database must be populated, also if the xml file doesn't contain the table defined in several schemas, DBUnit throws the AmbiguousTableNameException exception on that table.

I found that there are 3 solutions to solve this behavior:

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

In my case, I can only apply the solution 1, but even if I adopt it, I got the same exception.

The table that gives me problems is defined in 3 schemas and I don't have the opportunity to act on it in any way.

Please, someone could help me?

解决方案

I found the solution: I specified the schema in the name of the tables and I have set to true the property http://www.dbunit.org/features/qualifiedTableNames (corresponding to org.dbunit.database.FEATURE_QUALIFIED_TABLE_NAMES).

By this way, my xml code to populate tables look like:

<?xml version='1.0' encoding='UTF-8'?>
<dataset>
  <SCHEMA.TABLE ID_FIELD="1" />
</dataset>

where SCHEMA is the schema name, TABLE is the table name.

To se the property I've used the following code:

DatabaseConfig dBConfig = dBConn.getConfig(); // dBConn is a IDatabaseConnection
dBConfig.setProperty(DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES, true);

这篇关于Oracle + dbunit引发AmbiguousTableNameException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆