【问题标题】:org.dbunit.dataset.NoSuchTableException, but table existsorg.dbunit.dataset.NoSuchTableException,但表存在
【发布时间】:2016-06-17 02:21:06
【问题描述】:

H2 1.4.191.
数据库单元 2.5.1。
如何解决这个问题?
3例代码及结果:

org.dbunit.dataset.NoSuchTableException: category
org.dbunit.dataset.NoSuchTableException: Category
org.dbunit.dataset.NoSuchTableException: CATEGORY
//
<dataset>
<Category categoryId="9223372036854775806"
      categoryName="NAME"
      categoryParentId="9223372036854775805"/>   
</dataset>
//
CREATE TABLE Category (
  categoryId       INT          AUTO_INCREMENT,
  categoryName     VARCHAR      NOT NULL,
  categoryParentId INT          NOT NULL,
  PRIMARY KEY (categoryId)
)
//Check - tried to recreate
org.h2.jdbc.JdbcSQLException: Table "CATEGORY" already exists; 

【问题讨论】:

  • 您是否使用 DTD 加载 XML 文件?如果可以,您也可以发布吗?

标签: java sql junit h2 dbunit


【解决方案1】:

有时当您使用 dbunit 时,您需要定义您尝试使用表的架构,也许您可​​以尝试添加

<dataset>
<schema.Category categoryId="9223372036854775806"
      categoryName="NAME"
      categoryParentId="9223372036854775805"/>   
</dataset>

如果不检查您正在使用的数据源,可能您没有指向正确的数据库或架构。

对于 dbunit,我们有一些 properties 考虑使用 Qualified table names 属性,如下所示。

DatabaseConfig dBConfig = dBConn.getConfig(); // dBConn is a IDatabaseConnection
dBConfig.setProperty(DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES, true);

【讨论】:

  • 谢谢!但是应该如何指定呢?我正在使用默认的“测试”模式。 “
  • 我在回复中添加了配置
  • 再次非常感谢您!我已经完成了“result.getConfig().setProperty(DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES, true);”正如你所说,但问题仍然存在:org.dbunit.dataset.NoSuchTableException: test.Category
  • 尽量全部用大写,还有不区分大小写的属性
猜你喜欢
  • 2011-07-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-17
  • 2018-08-02
  • 2022-01-13
相关资源
最近更新 更多