我运行测试时遇到以下错误:
org.dbunit.dataset.NoSuchColumnException: myTable.MYFIELD - (Non-uppercase input column: myfield) in ColumnNameToIndexes cache map. Note that the map's column names are NOT case sensitive.
at org.dbunit.dataset.AbstractTableMetaData.getColumnIndex(AbstractTableMetaData.java:117)
我在org.dbunit.dataset.AbstractTableMetaData#getColumnIndex中设置了一个断点,并发现了以下内容.在IntelliJ Idea中,该方法如下所示:
public int getColumnIndex(String columnName) throws DataSetException
{
logger.debug("getColumnIndex(columnName={}) - start", columnName);
if(this._columnsToIndexes == null)
{
// lazily create the map
this._columnsToIndexes = createColumnIndexesMap(this.getColumns());
}
String columnNameUpperCase = columnName.toUpperCase();
Integer colIndex = (Integer) this._columnsToIndexes.get(columnNameUpperCase);
if(colIndex != null)
{
return colIndex.intValue();
}
else
{
throw new NoSuchColumnException(this.getTableName(), columnNameUpperCase,
" (Non-uppercase input column: "+columnName+") in ColumnNameToIndexes cache map. " +
"Note that the map's column names are NOT case sensitive.");
}
}
this.getColumns()的值不包含任何Column.columnName与参数columnName匹配的列.因此,colIndex变为null并抛出异常.
看起来DBUnit正在寻找错误的表元数据中的列索引.
我怎样才能解决这个问题?
注意:我从其他人那里继承了这段代码(没写过).