开发者

Simulate trigger with dbUnit

开发者 https://www.devze.com 2023-04-03 06:55 出处:网络
I\'m using dbUnit to put test data in DB with dataset like <dataset> <TABLE_1 PRIMARY_KEY_COL=\"10000001\" OTHER_COL=\"Some Text\"/>

I'm using dbUnit to put test data in DB with dataset like

     <dataset>
        <TABLE_1 PRIMARY_KEY_COL="10000001" OTHER_COL="Some Text"/>
     </dataset>

My problem is that there's on-insert trigger in db that populates child records into TABLE_2. So when I try to

   DatabaseOperation.DELETE.execute();

at tearDown() it fails with java.sql.SQLException: O开发者_运维百科RA-02292: integrity constraint (TABLE_2_TABLE_1_FK) violated - child record found.

Is there any way to simulate on-delete trigger for TABLE_1 to delete child records with dbUnit and do not add trigger into DB?


We do not have triggers in our databases, but we do use dbunit and this might work for you:

You can have a different dataset for the DELETE operation that includes the table where the trigger inserts data into. Order is important so dbunit can do the delete or insert operation on the table that references TABLE_1 first...

<dataset>
    <TABLE_WITH_TRIGGERED_DATA_HERE...>
    <TABLE_1 PRIMARY_KEY_COL="10000001" OTHER_COL="Some Text"/>
 </dataset>


I just put two links here, they should be enough

http://www.dbunit.org/apidocs/org/dbunit/operation/TruncateTableOperation.html

http://www.dbunit.org/bestpractices.html#nocleanup

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号