did you also have a look at the DatabaseOperation.TRANSACTION? It should allow to insert a complete dataset within one jdbc transaction. This way you wouldn't have to disable any of your constraints.
DatabaseOperation.TRANSACTION(DatabaseOperation.INSERT).execute(connection, dataSet);
You probably have to take care of the dbunit Batch-Statements which write to the db after reaching the batch size. Therefore you might need to provide a custom IStatementFactory (DatabaseConfig.PROPERTY_STATEMENT_FACTORY) which does not execute the batch for each table but only once at the very end. Maybe the dbunit SimplePreparedStatement would do the job?
Please feel free to play around with my above thoughts and don't be angry if they won't work cause I did not test that stuff...
> In HSQLDB you can do the following in your setup();
>
> dbUnitConnection.getConnection().prepareStatement("set
> referential_integrity FALSE").execute();
>
> ...where dbUnitConnection is the DBUnit IConnection. Then do the load
> using a database operation (e.g. DatabaseOperation.REFRESH). Then do this...
>
> dbUnitConnection.getConnection().prepareStatement("set
> referential_integrity TRUE").execute();
>
> The second idea just involves making a normal DBUnit XML dataset file
> (see
http://www.dbunit.org/components.html#FlatXmlDataSet) and then
> copying the XML for the user data to the end and modifying it by hand
> (or search & replace). If you use a REFRESH operation then DBUnit will
> insert data if it's not already there (based on the primary key of the
> database table) or update the row if the primary key already exists.
>
> Dave S-B
>
> TheStijn wrote:
> > thanks for the suggestions.
> >
> > I looked for disabling the constraints and found solutions for MySQL and
> > such (adding &sessionVariables=FOREIGN_KEY_CHECKS=0 to the URL).
> > However, I am using HSQLDB and this solution does not work. Do you have any
> > idea on how to manage this for HSQLDB?
> >
> > Your second sounds promising but I have to admit that I have no idea how to
> > implement this in XML.
> > How can you update an existing row with dbunit?
> >
> > tx again,
> > Stijn
> >
> >
> > Dave S-B wrote:
> >
> >> Presumably your application (i.e. Hibernate) manages to do this, so
> >> you'd have to get DBUnit to do it in the same way. I can only think of
> >> two ways;
> >>
> >> 1. Disable the constraints whilst you load the data. This is what I do
> >> all the time. The SQL will be specific to your database, but basically,
> >> disable constraints before you do the DBUnit load, then enable them
> >> afterwards.
> >>
> >> 2. Make it a 2-stage process in the DBUnit XML file. I'm assuming that
> >> you can add records into the user table with a NULL customer_id. So
> >> remove all the customer_ids from the user XML and have that first in the
> >> XML, then have the customer XML, then have a copy of the user XML *with*
> >> the customer_id in. Using a REFRESH operation the first lot of user data
> >> will get inserted (no customer_id), then the customer data, then the
> >> user data will get updated with the customer_ids included. Not very
> >> pretty, but I believe it'll work.
> >>
> >> Dave S-B
> >> Lledr Solutions
> >>
> >> TheStijn wrote:
> >>
> >>> Hi,
> >>>
> >>> I have a table user and a table customer which can be linked by a
> >>> one-to-one
> >>> relationship; meaning a user can reference 1 customer and vice-versa.
> >>>
> >>> I'm a bit stuck on how to set for instance a customer on a user since
> >>> this
> >>> customer is not defined yet:
> >>>
> >>> <user user_id="1" ... customer_id="2" />
> >>>
> >>> <customer customer_id="2" ... user_id="1" />
> >>>
> >>> DBUnit throws an SQL exception when trying to insert the user since it
> >>> references a customer that was not created yet. The error is logical
> >>> since
> >>> there is a DB constraint on this field.
> >>>
> >>> My question is, how to go around this problem with DBUnit in XML without
> >>> dropping the DB constraint obviously and if possible also without doing a
> >>> 'manual' update of user in my unit test?
> >>>
> >>> many thanks,
> >>> Stijn
> >>>
> >>> ------------------------------------------------------------------------
> >>>
> >>>
> >>> No virus found in this incoming message.
> >>> Checked by AVG - www.avg.com
> >>> Version: 8.5.375 / Virus Database: 270.12.92/2203 - Release Date:
> >>> 06/26/09 05:53:00
> >>>
> >>>
> >>>
> >> ------------------------------------------------------------------------------
> >> _______________________________________________
> >> dbunit-user mailing list
> >>
dbunit-user@...
> >>
https://lists.sourceforge.net/lists/listinfo/dbunit-user> >>
> >>
> >>
> >
> >
> > ------------------------------------------------------------------------
> >
> >
> > No virus found in this incoming message.
> > Checked by AVG - www.avg.com
> > Version: 8.5.375 / Virus Database: 270.12.92/2203 - Release Date: 06/26/09 05:53:00
> >
> >
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> dbunit-user mailing list
>
dbunit-user@...
>
https://lists.sourceforge.net/lists/listinfo/dbunit-user>