使用 DBUnit 测试 JPA/Hibernate 实体
我在某些实体上遇到了一些问题,特别是在使用 JPA/Hibernate 和 DBUNIT 时。 当我尝试构建项目时遇到了这个错误。
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)
如果配置属性如下,错误就会消失
username : usera
password : usera
schema : usera
dbunit version : 2.4.2
如果配置属性如下,则会发生错误
username : usera
pasword : usera
schema : schemab
dbunit version > 2.4.2 (e.g. 2.4.4)
看起来如果shema名称与用户名相同并且dbunit版本是2.4.2,那么它就可以工作。如果模式名称与用户名不同,并且 dbunit 版本是大于 2.4.2 的任何版本(我尝试了 2.4.3 和 2.4.4),则会发生错误。
以下是一些详细信息
表 DDL
CREATE TABLE CONTENTDOCUMENT (
ID bigint(20) NOT NULL AUTO_INCREMENT,
CONTENT varchar(255) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
数据库版本:
MySql 5.5.17 MySQL Community Server (GPL)
JPA/Hibernate 实体(摘要)-
@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>
<CONTENTDOCUMENT ID="1" CONTENT="TestContent1"/>
<CONTENTDOCUMENT ID="2" CONTENT="TestContent2" />
</dataset>
有任何线索吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
插入数据时尝试指定dtd文件。
Try to specify dtd file when you are inserting data.