【发布时间】:2011-11-21 16:21:25
【问题描述】:
根据 DBUnit 文档 link,它应该支持在使用 DatabaseSequenceFilter 时使用 CLEAN_INSERT。
尝试此操作时出现以下异常
com.sybase.jdbc2.jdbc.SybSQLException: Dependent foreign key constraint violation in a referential integrity constraint. dbname = 'my_db', table name = 'tbl_child', constraint name = 'fk_tbl_child_parentid'.
我的表格如下所示:
CREATE TABLE dbo.tbl_parent
(
parent_id numeric(19,0) IDENTITY,
...
)
CREATE TABLE dbo.tbl_child
(
child_id numeric(19,0) IDENTITY,
parent_id numeric(19,0) NOT NULL,
...
)
ALTER TABLE dbo.tbl_child
ADD CONSTRAINT fk_tbl_child_parentid
FOREIGN KEY (parent_id)
REFERENCES dbo.tbl_parent (parent_id)
我的 DBUnit 数据集如下所示:
<dataset>
<tbl_parent parent_id="41" ... />
<tbl_child child_id="1361" parent_id="41"/>
</dataset>
因此,在我有此代码的测试类中,如果数据已存在于数据库中并且由于外键约束而无法删除,则会出现错误
@Before
public void setUp() throws Exception {
InsertIdentityOperation.CLEAN_INSERT.execute(getConnection(), getDataSet());
}
有趣的是,一种解决方法是使用 REFRESH 而不是 CLEAN_INSERT,但这并不理想,因为垃圾数据可能驻留在数据库中,从而导致副作用:
@Before
public void setUp() throws Exception {
InsertIdentityOperation.REFRESH.execute(getConnection(), getDataSet());
}
有没有人能够让这个 CLEAN_INSERT 与 Sybase 和外键一起使用?从阅读其他帖子来看,MySQL 存在类似的问题,所以这里可能存在一个常见问题(或者我不明白)
[编辑]
在再次遇到相同问题后,我现在添加了自己的解决方法。
我正在使用 Sybase ASE 15 + DBUnit 2.4.8
【问题讨论】:
标签: constraints sap-ase dbunit