We have been using HSQL in-memory along with DBUnit for unit testing lately, and I found an issue using the most recent version of each. Basically, HSQL has added a new data type, BOOLEAN, which replaces BIT. But DBUnit is not updated to support this, and an error is throw when you attempt to insert some BOOLEAN data using DBUnit.
The error looks like this:WARNING - TABLE.COLUMN data type (16, 'BOOLEAN') not recognized and will be ignored. See FAQ for more information.
HsqlDataTypeFactory.java
package company.project.test; import org.apache.commons.logging.*; import org.dbunit.dataset.datatype.*; import java.sql.*; public class HsqlDataTypeFactory extends DefaultDataTypeFactory { private static final Log log = LogFactory.getLog(HsqlDataTypeFactory.class); public DataType createDataType(int sqlType, String sqlTypeName) throws DataTypeException { if (sqlType == Types.BOOLEAN) { return DataType.BOOLEAN; } return super.createDataType(sqlType, sqlTypeName); } }
Then, in order to use this data type factory, just set a property on the IDatabaseConnection DBUnit object in your code (here is an example method):
protected IDatabaseConnection getConnection() throws Exception { IDatabaseConnection connection = new DatabaseConnection(dataSource.getConnection()); DatabaseConfig config = connection.getConfig(); config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new HsqlDataTypeFactory()); return connection; }


It looks like an HsqlDataTypeFactory has been added to the DBUnit project nine months ago:
http://cvs.sourceforge.net/viewcvs.py/dbunit/dbunit/src/java/org/dbunit/ext/hsqldb/
This however is not in the latest DBUnit release (version 2.1) from May 2004 so if you want it from DBUnit, you need to build DBUnit from source.
Alon
This is great. Thanks.
But how do I do this if I’n calling dbunit as an ant task?
I believe you just set it as a property in the dbunit ant task like so:
<taskdef name=”dbunit”
classname=”org.dbunit.ant.DbUnitTask”
classpathref=”build.class.path”
datatypeFactory=”org.dbunit.ext.hsqldb.HsqlDataTypeFactory”/>
Thanks for that! Since DBUnit still does not support BOOLEAN in HSQLDB, this was a great help for me and my computer science class project
Why they don’t include it in the stable release is a uncertain, still…?!
I make these steps, but my dbUnit not recnizes a boolean dataType, this is my getConnection() method:
protected IDatabaseConnection getConnection() throws Exception {
// load the jdbc driver
Class.forName(“org.hsqldb.jdbcDriver”);
IDatabaseConnection connection =
new DatabaseConnection( DriverManager.getConnection(
“jdbc:hsqldb:hsql://localhost:1701″, “sa”, “” ) );
DatabaseConfig config = connection.getConfig();
config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY,
new HsqldbDataTypeFactory());
return connection;
}
Somebody can help me?
Thanksss