wildcatsの日記

赤羽在住でIT関係の会社の社長やってます。

DBUnit

テーブルのFKをバシバシ設定するとsetUp()でこけてしまうケースがありますな。
初期化でテーブルをどの順序で削除してるんだろう?
いろいろと試してみたんだけど現在の仕様だとちょっと困るので
ソースコードを読んでみて直せるようなら直してみます。

追記:アレ?特におかしなことはしてないな。単にテーブル削除の順序を間違えただけか。。。orz
追追記:FK違反で違反対象項目がエラーメッセージに出ないのはMySQLJDBCドライバの問題かもしれない。
MSDEで試してみると


java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]DELETE ステートメントは COLUMN REFERENCE で、
制約 'FK__Table_02__Table___79A81403' と矛盾しています。
矛盾が発生したのは、データベース 'test'、テーブル 'Table_02', column 'Table_03_id' です。
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processErrorToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSExecuteRequest.processReplyToken(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSRequest.processReply(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplStatement.getNextResultType(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonTransitionToState(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.postImplExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.commonExecute(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.executeInternal(Unknown Source)
at com.microsoft.jdbc.base.BaseStatement.execute(Unknown Source)
at org.dbunit.database.statement.SimpleStatement.executeBatch(SimpleStatement.java:54)
at org.dbunit.operation.DeleteAllOperation.execute(DeleteAllOperation.java:112)
at org.dbunit.operation.CompositeOperation.execute(CompositeOperation.java:67)
at org.dbunit.DatabaseTestCase.executeOperation(DatabaseTestCase.java:87)
at org.dbunit.DatabaseTestCase.setUp(DatabaseTestCase.java:104)
at Main.setUp(Main.java:14)
at junit.framework.TestCase.runBare(TestCase.java:125)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
こういう風にきっちりとエラーメッセージが出ますな。
あとDBUnitのテーブル削除順序はFlatXmlDataSetの場合はXMLファイルに定義された順に削除してるみたい。