Dbunit在Oracle下需要注意的问题

Kingonion 2007-06-14

公司准备把数据库把MYSQL换成oracle。系统有用dbunit写的测试DAO的代码。但跑起来的时候总是有AmbiguousTableNameException这个一场抛出在CLEAN_INSTALL的时候。上网找了

http://dbunit.sourceforge.net/faq.html#ambiguoustablenameexception

引用

WhyIgeta"AmbiguousTableNameException"?

ThiserroroccurswhennoschemaisspecifiedandthatDbUnitdetectthatitisgettingcolumnsinformationfrommultipletableshavingthesamenameandlocatedindifferentschemas.

Youcansolvethisprobleminthreedifferentways:

1.Providetheschemanamewhencreatingthedatabaseconnection.NotethatforOracleyoumustspecifytheschemanameinuppercase.

2.Ensurethattheconnectionisrestrictedtoaccessonlyoneschema.

3.Enablethequalifiedtablenamesfeature.

开始的时候以为这里的databaseconnection是javax里的Connection。其实这里的是dbunit里面的IDatabaseConnectiondbUnitConn=newDatabaseConnection(conn);

换成newDatabaseConnection(conn,SCHEMA_NAME)就ok了。注意SCHMEA_NAME需要大写。

相关推荐