0

I have two tables, one of table A's fields references table B's field, I use annotation @DatabaseSetup to do the importing of xml file, and I wrote both table A and table B's data in the dataset in the xml file. when I run the unit test, it says INSERT on table A caused a violation of foreign key constraint for key(0).

how to express the reference relationship between the two tables?

NullPointer
  • 412
  • 7
  • 17

1 Answers1

0

I presume your dataset XML file looks something along the lines of:

<TABLE_A ID="1"/>

<TABLE_B ID="1" TABLE_A_ID="1"/>

This violation could occur if:

  • Your second row contains an value for the foreign key reference that doesnt exist e.g.

<TABLE_A ID="1"/>

<TABLE_B ID="1" TABLE_A_ID="2"/>

  • Your dataset file inserts the rows in the wrong order e.g:

<TABLE_B ID="1" TABLE_A_ID="1"/>

<TABLE_A ID="1"/>

If you provide your dataset file and Db Unit Test I can be more specific

Eduardo
  • 6,900
  • 17
  • 77
  • 121