Kiva
Kiva

Reputation: 9363

Unitils/DBunit and database test

I want to try to make unit test with DBUnit but I have a problem with my dataset.

Here is my persistence object:

@Entity
@Table(name = "personnes")
public class Personne implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer pk;

    @Column
    private String name;
}

And my dataset:

<?xml version='1.0' encoding='UTF-8'?>
<dataset>
    <personnes name="toto"  pk="1" />
</dataset>

My problem is with the name column, I get this error:

org.dbunit.dataset.NoSuchColumnException: personnes.NAME -  (Non-uppercase input column: name) in ColumnNameToIndexes cache map. Note that the map's column names are NOT case sensitive.

I don't understand why dbunit search a column "NAME" whereas my column is "name".

Thanks for your help.

Upvotes: 4

Views: 7067

Answers (4)

Brian Hoover
Brian Hoover

Reputation: 7991

I've been fighting this for a while, and keep coming back to this issue, which doesn't seem to have a solution yet.

In Unitils 3.4.1, they added a new property, org.dbunit.database.IMetadataHandler.implClassName

In my unitils.properties file, I added the following line

org.dbunit.database.IMetadataHandler.implClassName=org.dbunit.ext.mysql.MySqlMetadataHandler

Yes, I know, according to Unitils' website, there is no version 3.4.1, but you can get the latest version via Maven.

link to issue report

Upvotes: 4

Michal Biros
Michal Biros

Reputation: 435

Try to set datatype factory for your databases.

All available factories can be found on this link. http://dbunit.sourceforge.net/apidocs/org/dbunit/dataset/datatype/IDataTypeFactory.html

Choose factory which belongs to your database.

Implement method setUpDatabaseConfig in your test class and set factory.

protected void setUpDatabaseConfig(DatabaseConfig config) {
   config.setProperty( DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new OracleDataTypeFactory() );
}

Upvotes: 0

TrueDub
TrueDub

Reputation: 5070

You need to set the following to true

DatabaseConfig.FEATURE_CASE_SENSITIVE_TABLE_NAMES

within your DatabaseConfig object.

See org.dbunit.dataset.NoSuchTableException: Did not find table 'xxx' in schema 'null'

Upvotes: 0

rudolfson
rudolfson

Reputation: 4146

Since you don't specify the column name in the mapping, I guess the underlying ORM framework generates the column name "NAME" for it.

To resolve this error/warning, you could add the column name to the mapping

@Column( name = "name")

resulting in a lower-case column name or use upper-case notation in your dataset

<personnes NAME="toto"  pk="1" />

leaving the upper-case column name.

Upvotes: 0

Related Questions