H2
IDataTypeFactory
H2DataTypeFactory
maps H2’s BOOLEAN to DataType.BOOLEAN and UUID to DataType.NVARCHAR,
delegating everything else to DefaultDataTypeFactory. Register it via
DatabaseConfig.PROPERTY_DATATYPE_FACTORY — see
Properties and
Connections & Configuration.
IMetadataHandler
H2MetadataHandler
excludes the INFORMATION_SCHEMA schema from getTables() results. H2 2.x rewrote
INFORMATION_SCHEMA to be SQL-standard-compliant, and most of its internal tables now
report the same JDBC TABLE_TYPE (BASE TABLE) as real user tables instead of the
SYSTEM TABLE type H2 1.x used, so dbUnit’s default table-type filter
(PROPERTY_TABLE_TYPE, {"TABLE"}) no longer screens
them out on its own. Without this handler, a connection queried without a fixed single
schema (an admin user, or qualified table
names with no schema configured) gets 15 bogus system tables mixed into its table
listing. See IMetadataHandler for how the fix
works and why it’s implemented this way rather than centrally in DatabaseDataSet.
Connection Preconfiguration Class
H2Connection wraps
a JDBC Connection and pre-registers both H2DataTypeFactory and H2MetadataHandler:
IDatabaseConnection connection = new H2Connection(jdbcConnection, schema);Known Quirks
Connecting to H2 2.x with a hand-assembled DatabaseConnection instead of
H2Connection loses the INFORMATION_SCHEMA exclusion above — register
H2MetadataHandler on PROPERTY_METADATA_HANDLER explicitly if H2Connection isn’t an
option. This is new as of dbUnit’s H2 2.x support; H2 1.x never needed it.


