I would like to initialize HSQL db with DBUnit. I have a table like this one:
table EMPLOYEE( id, name, manager_id) // manager_id is nullable
CONSTRAINT "fk_manager" FOREIGN KEY ("manager_id")
REFERENCES EMPLOYEE("id)
The problem is when I try to initialize with this dataset:
<dataset>
<EMPLOYEE id="2" name="John" manager_id="5"/> <!--Doe is the John's manager-->
<EMPLOYEE id="3" name="Doe" manager_id="4"/> <!--Kong is the Does's manager-->
<EMPLOYEE id="4" name="Kong" manager_id="2"/> <!-- John is the Kong's manager-->
</dataset>
I have this exception:
Caused by: org.hsqldb.HsqlException: integrity constraint violation: foreign key no parent; fk_manager table: EMPLOYEE
How to solve that error? Thanks
You need to insert the first row without the
managerIdand add this value after inserting the row containing itsmanagerIdIt is also possible to turn off foreign key constraint checks during the inserts. Your dataset should be consistent and should not include foreign key references to non-existent rows.
http://hsqldb.org/doc/2.0/guide/management-chapt.html#mtc_database_settings