我正在尝试通过填充具有TIMESTAMP(6) WITH TIME ZONE
如下类型列的表来设置数据库单元测试的数据:
<timetable START_TIME="2015-03-01 10.00.00.000000000" END_TIME="2015-03-02 10.00.00.000000000"/>
但是当我运行测试时,我不断收到以下异常:
org.dbunit.dataset.NoSuchColumnException: TIMETABLE.START_TIME - (Non-uppercase input column: START_TIME) in ColumnNameToIndexes cache map. Note that the map's column names are NOT case sensitive.
at org.dbunit.dataset.AbstractTableMetaData.getColumnIndex(AbstractTableMetaData.java:117)
at org.dbunit.operation.AbstractOperation.getOperationMetaData(AbstractOperation.java:89)
at org.dbunit.operation.AbstractBatchOperation.execute(AbstractBatchOperation.java:143)
at org.dbunit.operation.CompositeOperation.execute(CompositeOperation.java:79)
at com.github.springtestdbunit.DbUnitRunner.setupOrTeardown(DbUnitRunner.java:194)
at com.github.springtestdbunit.DbUnitRunner.beforeTestMethod(DbUnitRunner.java:66)
at com.github.springtestdbunit.DbUnitTestExecutionListener.beforeTestMethod(DbUnitTestExecutionListener.java:185)
at org.springframework.test.context.TestContextManager.beforeTestMethod(TestContextManager.java:249)
我为时间戳字段尝试了不同的格式,包括添加时区后缀 +XX:XX2015-03-01 10.00.00.000000000 +00.00
无济于事。我还尝试使用 VM 参数运行测试,-Duser.timezone=UTC
但这也无济于事。
有谁知道如何做到这一点?
编辑 1
我在控制台中注意到以下警告:
2016-05-31 14:54:23 WARN SQLHelper:429 - TIMETABLE.START_TIME data type (-101, 'TIMESTAMP(6) WITH TIME ZONE') not recognized and will be ignored. See FAQ for more information.
2016-05-31 14:54:23 WARN SQLHelper:429 - TIMETABLE.END_TIME data type (-101, 'TIMESTAMP(6) WITH TIME ZONE') not recognized and will be ignored. See FAQ for more information.
所以看起来 Dbunit 不支持TIMESTAMP WITH TIME ZONE
数据类型并忽略它,因此出现NoSuchColumnException
异常
编辑 2
实际上 dbunit 已经TIMESTAMP
通过类支持数据类型OracleDataTypeFactory
。配置将如下所示:
<bean id="oracleDataTypeFactory" class="org.dbunit.ext.oracle.OracleDataTypeFactory"/>
<bean id="dbUnitDatabaseConfig" class="com.github.springtestdbunit.bean.DatabaseConfigBean">
<property name="datatypeFactory" ref="oracleDataTypeFactory" />
</bean>
不幸的是,在这些配置更改之后,数据类型问题仍然存在,因为 dbunit DatabaseConfig.datatypeFactory 属性被 DbUnitTestExecutionListener 重新设置为DefaultDataTypeFactory
不支持 TIMESTAMP 数据类型的默认值