Chizh
Chizh

Reputation: 1029

Simulate trigger with dbUnit

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: ORA-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?

Upvotes: 4

Views: 1170

Answers (2)

c_maker
c_maker

Reputation: 19986

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>

Upvotes: 1

Related Questions