Details

    • Type: Bug
    • Status: Open
    • Priority: Critical
    • Resolution: Unresolved
    • Affects Version/s: 3.1
    • Fix Version/s: None
    • Component/s: dbunit
    • Labels:
      None
    • Environment:
      unitils 3.1
      dbunit 2.4.8
      mysql database

      Description

      test case :
      crash when inserting data using xml dataset before running any test

      stack trace :
      Caused by: org.dbunit.dataset.NoSuchColumnException: mytable.MYCOLUMN - (Non-uppercase input column: mycolumn) 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:140)
      at org.dbunit.operation.CompositeOperation.execute(CompositeOperation.java:79)
      at org.unitils.dbunit.datasetloadstrategy.impl.CleanInsertLoadStrategy.doExecute(CleanInsertLoadStrategy.java:45)
      at org.unitils.dbunit.datasetloadstrategy.impl.BaseDataSetLoadStrategy.execute(BaseDataSetLoadStrategy.java:44)
      ... 20 more

      explanation :
      in DbUnit, the property PROPERTY_METADATA_HANDLER in DatabaseConfig has a value set to new DefaultMetadataHandler()
      to make it work when using a mysql db this PROPERTY_METADATA_HANDLER property should be set to new MySqlMetadataHandler()
      this MySqlMetadataHandler class is never instanciated neither in dbunit nor in unitils-dbunit, it seems this class have been totally forgotten

      bug fix :
      ideally this property should be settable in unitils.properties
      but for now, I fixed it directly in unitils-dbunit as follow

      org.unitils.dbunit.DbUnitModule.createDbUnitConnection() {

      ...
      // Create connection
              DbUnitDatabaseConnection connection = new DbUnitDatabaseConnection(dataSource, dbSupport.getSchemaName());
              
      // check if database is MySQL
              boolean isMySQL = false;
              try {
               String databaseProductName = connection.getConnection().getMetaData().getDatabaseProductName();
      if (databaseProductName.equals("MySQL")) {
      isMySQL = true;
      logger.info("Database product name = " + databaseProductName + ", set DatabaseConfig.PROPERTY_METADATA_HANDLER to new MySqlMetadataHandler()");
      }
      } catch (SQLException e) {
      e.printStackTrace();
      }

              DatabaseConfig config = connection.getConfig();

              // if database is MySQL, reset PROPERTY_METADATA_HANDLER to use MySQL specific Handler
              if (isMySQL) {
               config.setProperty(DatabaseConfig.PROPERTY_METADATA_HANDLER, new MySqlMetadataHandler());
              }
      ...
      }

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              enji Nelly JOUFFRE
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated: