I get the following error while running my tests:
org.dbunit.dataset.NoSuchColumnException: myTable.MYFIELD - (Non-uppercase input column: myfield) in ColumnNameToIndexes cache map. Note that the map column names are NOT case sensitive. at org.dbunit.dataset.AbstractTableMetaData.getColumnIndex(AbstractTableMetaData.java:117)
I set a breakpoint in org.dbunit.dataset.AbstractTableMetaData#getColumnIndex and found the following. In IntelliJ Idea, the method is as follows:
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 column names are NOT case sensitive."); } }
The value of this.getColumns() does not contain any Column with Column.columnName corresponding to the columnName parameter. Therefore, colIndex becomes null and an exception is thrown.
It looks like DBUnit is looking for the column index in the wrong table metadata.
How can i fix this?
Note. I inherited this code from someone else (did not write it).
source share