gpt4 book ai didi

java - DBUnit:NoSuchColumnException ColumnNameToIndexes 缓存映射中的非大写输入列。 map 的列名不区分大小写

转载 作者:行者123 更新时间:2023-11-29 05:49:36 25 4
gpt4 key购买 nike

我的 java 应用程序将您的信息存储在 MySql 数据库版本 8 中。用户信息和密码存储在该数据库中。我正在实现一个集成测试来测试使用 dbunit 验证数据库中用户的方法。测试方法运行后出现如下错误。

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

我通过 MySql Workbench 检查表和列都是大写的,所以显示的错误消息没有意义。有谁知道是什么导致了这个异常?

测试上下文.xml

unitils.properties

unitils.module.hibernate.enabled=true
unitils.module.jpa.enabled=false
unitils.module.easymock.enabled=false

database.url=jdbc:mysql://192.168.0.12:3306/db_ca?useUnicode=true&characterEncoding=UTF-8&serverTimezone=America/Sao_Paulo
database.driverClassName=com.mysql.jdbc.Driver
database.userName=root
database.password=9999
database.schemaNames=db_main, db_ca
database.dialect=mysql

unitils.module.database.className=com.myapplication.test.unitils.SingleConnectionDatabaseModule
DatabaseModule.Transactional.value.default=disabled

DbUnitModule.DataSet.loadStrategy.default=org.unitils.dbunit.datasetloadstrategy.impl.CleanInsertLoadStrategy

updateDataBaseSchema.enabled=true
dbMaintainer.script.locations=src/test/dbscripts
dbMaintainer.autoCreateExecutedScriptsTable=true
dbMaintainer.generateDataSetStructure.enabled=false
dbMaintainer.preserve.schemas=

在 src/test/dbscripts 中存在文件 001_SCRIPT_01.00.00

SET character_set_client = utf8mb4 ;
CREATE TABLE db_ca.ROLE (
ROLE_ID INT(11) NOT NULL AUTO_INCREMENT,
NAME VARCHAR(200) NOT NULL,
PRIMARY KEY (ROLE_ID)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

SET character_set_client = utf8mb4 ;
CREATE TABLE db_ca.USER (
USER_ID INT(11) NOT NULL AUTO_INCREMENT,
EMAIL VARCHAR(100) NULL DEFAULT NULL,
NAME VARCHAR(150) NOT NULL,
PASSWORD VARCHAR(200) NOT NULL,
PRIMARY KEY (USER_ID)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

SET character_set_client = utf8mb4 ;
CREATE TABLE db_ca.USER_ROLE (
ROLE_ID INT(11) NOT NULL,
USER_ID INT(11) NOT NULL,
PRIMARY KEY (ROLE_ID, USER_ID)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

/datasets/UserServiceTest.xml

<?xml version="1.0" encoding="UTF-8"?>
<dataset xmlns="db_ca">
<USER
USER_ID = "1"
EMAIL = "test@test.com"
NAME = "TEST"
PASSWORD = "e8d95a51f3af4a3b134bf6bb680a213a"
/>
<ROLE
ROLE_ID = "1"
NAME = "ADMIN"
/>
<USER_ROLE
USER_ID = "1"
ROLE_ID = "1"
/>
</dataset>

实体

@Entity
@Table(name = "USER", schema="db_ca")
public class User {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="USER_ID", nullable=false)
private Long id;

...
}

@Entity
@Table(name = "ROLE", schema="db_ca" )
public class Role {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="ROLE_ID", nullable=false)
private Long id;

...
}

类测试AccessServiceIT.java

@DataSet("/datasets/UsuarioServiceTest.xml")
@RunWith(UnitilsJUnit4TestClassRunner.class)
@SpringApplicationContext("testContext.xml")
public class AccessServiceIT {

@SpringBean("AccessServiceImpl")
private AccessService accessService;

@Test
public void accessTest() {
CredentialsBean credentialsBean = accessService.confirmLogon("test@test.com", "e8d95a51f3af4a3b134bf6bb680a213a");
assertEquals("test@test.com", credentialsBean.getLogon());
assertEquals(true, credentialsBean.isAuthenticated());
}
}

最佳答案

我找到了问题的解决方案。我只是将以下属性放在 unitils.properties 中,现在一切正常。

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

我在这里找到了解决方案 https://stackoverflow.com/a/39549867/3554659

我希望它能帮助正在经历同样错误的人。

关于java - DBUnit:NoSuchColumnException ColumnNameToIndexes 缓存映射中的非大写输入列。 map 的列名不区分大小写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55669050/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com