|
From: John L. <JLi...@Xi...> - 2006-01-10 17:10:18
|
I ran into this kind of issue and ended up resolving it myself by disabling all foreign key constraints between the tables found in the dataset before performing the delete. After the deletion, the constraints are re-enabled.
John
-----Original Message-----
From: Emanuel Barbosa [mailto:ema...@ed...]
Sent: Wednesday, January 04, 2006 12:04 PM
To: dbu...@li...
Cc: ema...@ho...
Subject: [dbunit-user] How disable foreign key constraint checks
Hi,
I want to delete the entire contents only of table present in the dataset.
Tables are sequenced appropriately in the dataset.
But I have some circular table (reference itself) and exception is thrown when DBUnit attempt to delete them:
org.objectweb.cjdbc.common.exceptions.driver.DriverSQLException: Message of cause: Request delete from hierarchys failed on backend localhost (Cannot delete or update a parent row: a foreign key constraint fails)
at org.objectweb.cjdbc.driver.Connection.execWriteRequest(Connection.java:1609)
at org.objectweb.cjdbc.driver.Statement.executeUpdateWithSkeleton(Statement.java:438)
at org.objectweb.cjdbc.driver.Statement.executeUpdate(Statement.java:345)
at org.objectweb.cjdbc.driver.Statement.execute(Statement.java:266)
at org.dbunit.database.statement.SimpleStatement.executeBatch(SimpleStatement.java:54)
at org.dbunit.operation.DeleteAllOperation.execute(DeleteAllOperation.java:97)
at org.dbunit.operation.CompositeOperation.execute(CompositeOperation.java:67)
at RCC.FreeTextMessageManagement.FreeTextLookupManagerTest.initialize(FreeTextLookupManagerTest.java:64)
at RCC.FreeTextMessageManagement.FreeTextLookupManagerTest.setUp(FreeTextLookupManagerTest.java:74)
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)
Any idea in how to solve this problem?
One solution is disable the foreign key constraint checks before delete the table contents (sql: SET FOREIGN_KEY_CHECKS=0;).
I think DBUnit probably has some way to do this. If true, the question is how?
Regards,
Emanuel Barbosa.
|