java DB单元;对表/列名称区分大小写的混淆

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2210429/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 20:03:29  来源:igfitidea点击:

DBunit; confusion over case sensitivity on table/column names

javacase-sensitivedbunitmysql5

提问by Jimmy

I'm getting this error when I start up my application

启动应用程序时出现此错误

Caused by: org.dbunit.dataset.NoSuchColumnException: CLIENT.ID -  (Non-uppercase input column: ID) in ColumnNameToIndexes cache map. Note that the map's column names are NOT case sensitive

I'm not too sure why I'm getting this, since my table/column names all all referenced in upper case(even though the message insists this shouldn't be an issue)

我不太确定为什么我会得到这个,因为我的表/列名称都以大写形式引用(即使消息坚持认为这不应该是问题)

My table :

我的桌子:

mysql> describe CLIENT;
+------------------+--------------+------+-----+---------+----------------+
| Field            | Type         | Null | Key | Default | Extra          |
+------------------+--------------+------+-----+---------+----------------+
| ID               | int(11)      | NO   | PRI | NULL    | auto_increment |
| jdoDetachedState | tinyblob     | YES  |     | NULL    |                |
| NAME             | varchar(255) | NO   |     | NULL    |                |
| ADDRESS1         | varchar(255) | YES  |     | NULL    |                |
| ADDRESS2         | varchar(255) | YES  |     | NULL    |                |
| COUNTRY          | varchar(255) | YES  |     | NULL    |                |
| COUNTY           | varchar(255) | YES  |     | NULL    |                |
| MAINPHONENUMBER  | varchar(255) | YES  |     | NULL    |                |
| POSTCODE         | varchar(255) | YES  |     | NULL    |                |
| SECTOR           | varchar(255) | YES  |     | NULL    |                |
| TOWN             | varchar(255) | YES  |     | NULL    |                |
| WEBSITEURL       | varchar(255) | YES  |     | NULL    |                |
+------------------+--------------+------+-----+---------+----------------+
12 rows in set (0.00 sec)

mysql> 

Snippet of my domain entity :

我的域实体的片段:

@Id
@GeneratedValue
@Column(name="ID")
private Integer id;

Snippet of test date I'm trying to force DBUnit to use:

测试日期片段我试图强制 DBUnit 使用:

<dataset>
  <CLIENT ID="-1"
    ADDRESS1="Endeavour House"
    ADDRESS2="Russell Rd"
    COUNTRY="England"
    COUNTY="Suffolk"
    MAINPHONENUMBER="0845 606 6067"
    NAME="Suffolk County Council"
    POSTCODE="IP1 2BX"
    SECTOR="Local Government"
    TOWN="Ipswich"
    WEBSITEURL="www.suffolk.gov.uk"/>
</dataset>

I can't think of anything else to try, have dropped tables and recompiled java code, any ideas?

我想不出还有什么可以尝试的,删除了表并重新编译了 Java 代码,有什么想法吗?

采纳答案by amorfis

Aren't you trying to put to database Client with ID already set? ID column is read-only, only database can "write" to it.

您不是要尝试将已设置 ID 的数据库 Client 放入数据库吗?ID 列是只读的,只有数据库可以“写入”它。

回答by Paul Podgorsek

I've also had this problem after adding a column to one of my entities (using an in-memory HSQL database).

在将一列添加到我的实体之一(使用内存中的 HSQL 数据库)后,我也遇到了这个问题。

I managed to solve this problem by simply deleting the temporary files that had previously been generated: mem:testdb.log, mem:testdb.properties and mem:testdb.script

我设法通过简单地删除以前生成的临时文件来解决这个问题:mem:testdb.log、mem:testdb.properties 和 mem:testdb.script

Why did this error occur? => A database schema is stored in the mem:testdb.script file and is not re-generated when the entity is modified.

为什么会出现这个错误?=> 数据库模式存储在 mem:testdb.script 文件中,并且在修改实体时不会重新生成。

回答by tak3shi

I have fixed the error by adding the mentioned column to my entity.

我通过将提到的列添加到我的实体来修复了错误。

回答by Bilbo Baggins

I ran into the same error, fortunately we had some other test written earlier and found that in most of the tutorials the format the way the xml is written is for the FlatXMLDataSet if you are using XML data set then the correct version is as follow checkout the link at the bottom for more information.

我遇到了同样的错误,幸运的是我们之前编写了一些其他测试,发现在大多数教程中,编写 xml 的格式是针对 FlatXMLDataSet 如果您使用的是 XML 数据集,那么正确的版本如下结帐底部的链接了解更多信息。

it should be in following format.

它应该是以下格式。

<?xml version="1.0" encoding="UTF-8"?>
<dataset>
    <table>
        <column>id</column>
        <column>name</column>
        <column>department</column>
        <column>startDate</column>
        <column>endDate</column>
        <row>
            <value>999</value>
            <value>TEMP</value>
            <value>TEMP DEPT</value>
            <value>2113-10-13</value>
            <value>2123-10-13</value>
        </row>
    </table>
</dataset>

For more information go to this link.

有关更多信息,请访问此链接。

http://dbunit.sourceforge.net/components.html#FlatXmlDataSet

http://dbunit.sourceforge.net/components.html#FlatXmlDataSet

One more time I faced this error in another project, we have a hierarchy of model class, some how hibernate used to create a table Role with 7 columns but while running it with DBUnit it was unable to create the columns(Only 5 were created) hence it was throwing this error, Solution : Manually created this table and 3 more relationship tables which were not created by hibernate.

又一次我在另一个项目中遇到这个错误,我们有一个模型类的层次结构,一些 hibernate 如何用来创建一个具有 7 列的表 Role 但是在使用 DBUnit 运行它时它无法创建列(只创建了 5 个)因此它抛出了这个错误,解决方案:手动创建这个表和另外 3 个不是由休眠创建的关系表。

回答by dres

this error goes away with mysql and hsql if you make format = flat

如果你使 format = flat,这个错误会随着 mysql 和 hsql 消失