DBUnit loses data

2 min read >

DBUnit loses data

Engineering Insights & Enterprise solutions

If not used properly Dbunit can lose data.

I’m using dbunit version 2.1 which has the following bug: when importing a file if the first row in the dataset file has missing columns, no further data from subsequent rows will be imported.

The solution when using the dbunit ant task will be to first perform an export operation to an already initialized database. At export ant operation specify the dtd location:

dbunit driver="com.vendor.jdbc.Driver userid="user
    password="password">
<export dest="export.xml" dtd=”dtd-file.dtd”/>
</dbunit>

<dbunit driver="com.vendor.jdbc.Driver" url="jdbc:vendor:mydatabase"
    userid="user" password="password">
<export dest="dtd-file.dtd" format="dtd"/>
</dbunit>

The “dtd” parameter from the first export task must be the same as the one from the second. The dtd parameter can be either
the file name or the path to the dtd file as its value will be filled in !DOCTYPE tag:

DOCTYPE dataset SYSTEM "dtd-dataset.dtd">

This way next time an import will be done specifying generated dtd (from the export task) will assure that data will be properly imported from the data-set file.
Other users have also faced this problem: http://sourceforge.net/mailarchive/message.php?msg_id=8286420.

Unlock innovation and digital transformation for your business.

Get in touch

We are always happy to talk

Phone

+40-21-223-7700

Email

hello@tremend.com

Address

165 Splaiul Unirii, Timpuri Noi Square,
TN Office 2 building, 4th floor,
District 3, Bucharest, Romania, 030134