简体   繁体   中英

Testing JPA/Hibernate entities using DBUnit

I've got some problems with some entities specifically with the use of JPA/Hibernate and DBUNIT. I came across this error when i tried to build the project.

Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 2.221 sec <<< FAILURE!
readDocumentById(com.bt.msm.ds.facade.DataServicesFacadeTest)  Time elapsed: 2.043 sec  <<< ERROR!
org.dbunit.dataset.NoSuchColumnException: CONTENTDOCUMENT.ID -  (Non-uppercase input column: ID) in ColumnNameToIndexes cache map. Note that the map's column names are NOT case sensitive.
    at org.dbunit.dataset.AbstractTableMetaData.getColumnIndex(AbstractTableMetaData.java:128)
    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)

The error disappears if the configuration properties are as follows

username : usera
password : usera
schema   : usera
dbunit version : 2.4.2

The error occurs if the configuration properties are as follows

username : usera
pasword : usera
schema :  schemab
dbunit version > 2.4.2 (e.g. 2.4.4)

It looks like if the shema name is the same as the username and the dbunit version is 2.4.2 then it works. If the schema name is not the same as the username and the dbunit version is any version greater than 2.4.2 ( i tried 2.4.3 and 2.4.4) then the error occurs.

Here are some details

Table DDL

CREATE TABLE CONTENTDOCUMENT (
  ID bigint(20) NOT NULL AUTO_INCREMENT,
  CONTENT varchar(255) DEFAULT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8

Database version:

MySql 5.5.17 MySQL Community Server (GPL)

JPA/Hibernate Entity (summary) -

@Entity
@Indexed
@Table(name="CONTENTDOCUMENT")

public class ContentDocument{
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="ID")
    public Long getId() {
        return id;
    }

    @Column(name="CONTENT")
    public String getContent() {
        return content;
    }
}

DBunit dataset

<dataset>
    <CONTENTDOCUMENT ID="1" CONTENT="TestContent1"/>
    <CONTENTDOCUMENT ID="2" CONTENT="TestContent2" />   
</dataset>

Any clues?

插入数据时尝试指定dtd文件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM