使用 dbUnit 模拟触发器
我使用 dbUnit 将测试数据放入数据库中,数据集如
<dataset>
<TABLE_1 PRIMARY_KEY_COL="10000001" OTHER_COL="Some Text"/>
</dataset>
我的问题是数据库中有插入触发器,可将子记录填充到 TABLE_2 中。因此,当我尝试
DatabaseOperation.DELETE.execute();
tearDown()时,它失败并出现java.sql.SQLException:ORA-02292:违反完整性约束(TABLE_2_TABLE_1_FK) - 找到子记录。
有没有办法模拟 TABLE_1 的删除触发器以使用 dbUnit 删除子记录并且不将触发器添加到 DB 中?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们的数据库中没有触发器,但我们使用 dbunit,这可能对您有用:
您可以为 DELETE 操作使用不同的数据集,其中包括触发器将数据插入到的表。顺序很重要,因此 dbunit 可以对首先引用 TABLE_1 的表执行删除或插入操作...
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...
我只是在这里放了两个链接,它们应该足够了
http://www. dbunit.org/apidocs/org/dbunit/operation/TruncateTableOperation.html
http://www.dbunit.org/bestpractices.html#nocleanup
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