org.dbunit.dataset.NoSuchTableException, but table exists

和自甴很熟 提交于 2019-12-12 16:22:17

问题


H2 1.4.191.
DbUnit 2.5.1.
How this can be fixed?
Code and results for 3 cases:

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; 

回答1:


Sometimes when you are using dbunit you need to define the schema from which you are trying to use the table, probably you could try to add

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

If not check the datasource that you are using, probably you are not pointing to the correct database or schema.

For dbunit we have some properties consider using the Qualified table names property as follows.

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


来源:https://stackoverflow.com/questions/35777580/org-dbunit-dataset-nosuchtableexception-but-table-exists

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!