Sunday, February 24, 2008

DBUnit Boolean issue

DBUnit is a nice procduct. In fact I'm not using it directly. I'm prefer going in declarative way with dbunit-maven-plugin. Why declarative way ? Well, all I need to do to populate database before executing JUnit test is to configure maven plugin and we are ready to go. The sweet thing is that data for storing in database is in xml format. XML is not SQL :) I've tested my application without any changes in HSQLDB, MySQL and Oracle without single change in data for testing. I mean no RDBMS specific SQL here, more to say, no SQL at all. Creation such datafile also is not a problem. DBUnit plugin can create it for you with the help of dbunit:export goal.

All is seems to be okay whyle you are not trying to persist Boolean value. For the first look, all is going wrong. I've spent a lot of time trying to understand WTF is going on. DBUnit does not insert boolean value, and says that column doesn't exist at all. It is damn fun when I know that column _exacly_ exists. Bug ? Feature ? /dev/hands error ? :)

As Google reported, I was not alone with this problem. And it is more a feature than a bug. Solution is here. So, adding ${dbunit.hack.Boolean} to plugin's configuration section works ! At HSQLDB profile of my parent pom.xml I have dbunit.hack.Boolean=org.dbunit.ext.hsqldb.HsqldbDataTypeFactory.

I'm happy, but how many another small bugs/features are in software, which are ready to eat wery easy 1-2-3 hours of our life ?

1 comment:

sionsmith said...


I have been having the same problem, at 1st I thought it was todo with the syntax of my xml for inserting booleans but clearly not.

Could you do me a massive favour and copy and paste your pom in here?