我有以下非常奇怪的 DBUnit 数据集:
<persons id = "1"
first_name ="TestName99"
second_name = "TestSecondName"
father_name = "TestFatherName"
phone_number = "123456789"
date_of_birth = "1985-12-12 00:16:14"
role = "ROLE_OWNER"
date_of_creation = "2016-09-23 23:09:28"
enable = "1" />
<carwash id = "1"
name = "TestCarWash"
address = "test car wash address "
phone_number = " 123456789"
box_count = "5"
first_shift = "08:00:00"
second_shift = "20:00:00"
created_by = "1"
date_of_creation = "2016-09-23 23:09:28"
enable = "1" />
<persons id = "2"
first_name ="TestName100"
second_name = "TestSecondName"
father_name = "TestFatherName"
phone_number = "123456789"
date_of_birth = "1985-12-12 00:16:14"
role = "ROLE_WASHERMAN"
date_of_creation = "2016-09-23 23:09:28"
carwash = "1"
enable = "1" />
最奇怪的认为是persons
表有外键carwash
但是这个列是可以为空的(因此你不能carwash
亲自找到id=1
)并且表在列carwash
中有 FKpersons
create_by
该方案导致将数据放入数据库中的特殊顺序。据我了解,默认情况下,DBUnit 不会根据数据集中提到的值的顺序将值放入 DB 中。因此,当这个数据集正在执行时,它会导致异常
MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`test_pitstop`.`persons`, CONSTRAINT `persons_ibfk_1` FOREIGN KEY (`carwash`) REFERENCES `carwash` (`id`))
有什么方法可以推动 DBUnit 将数据按 xml 中提到的字符串顺序放入 DB 中?