我对DBUnit的下面很奇怪的数据集: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
表中有FK到persons
列create_by
这个方案导致把数据放在数据库中的特殊顺序。据我了解,DBUnit不会根据数据集中提到的值的默认顺序将值存入数据库。因此,当这个数据集执行它导致异常
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提到?
我不想重写。我需要id = 1的人先放在DB中,而不是应该放在洗衣机中,并且只能在该人id = 2之后放入。默认情况下,DBUnit希望放置所有人,只有在洗车后才会导致异常 –