org.dbunit.database.AmbiguousTableNameException with MySQL 8



有人能帮我一下吗?

使用dbunit-maven-plugin-1.0-beta-3与mysql 8加载元数据到数据库表。

得到如下错误

org.apache.maven.lifecycle.LifecycleExecutionException: Error executing database operation: CLEAN_INSERT
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:719)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoExecutionException: Error executing database operation: CLEAN_INSERT
at org.codehaus.mojo.dbunit.OperationMojo.execute(OperationMojo.java:109)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
... 17 more
Caused by: org.dbunit.database.AmbiguousTableNameException: USERTABLE
at org.dbunit.dataset.OrderedTableNameMap.add(OrderedTableNameMap.java:198)
at org.dbunit.database.DatabaseDataSet.initialize(DatabaseDataSet.java:227)
at org.dbunit.database.DatabaseDataSet.getTableMetaData(DatabaseDataSet.java:275)
at org.dbunit.operation.DeleteAllOperation.execute(DeleteAllOperation.java:109)
at org.dbunit.operation.CompositeOperation.execute(CompositeOperation.java:79)
at org.dbunit.ant.Operation.execute(Operation.java:195)
at org.codehaus.mojo.dbunit.OperationMojo.execute(OperationMojo.java:100)
... 19 more

顺便说一句,我有两个数据库具有相同的表名。

仅供参考,它将与mysql- concontor -java-5.1.49一起工作。但是在我们的例子中,我们需要使用mysql连接器8.0.22.

谢谢。

这是一段pom dbunit配置,它为我解决了这个问题。

<schema>test_database</schema>
<dataTypeFactoryName>org.dbunit.ext.mysql.MySqlDataTypeFactory</dataTypeFactoryName>                    
<metadataHandlerName>org.dbunit.ext.mysql.MySqlMetadataHandler</metadataHandlerName>

顺便说一句,我有两个数据库具有相同的表名。

打开限定表名功能修复这个问题吗?如果用户有多个模式,dbUnit可能需要知道使用哪个模式。

例如,在功能页面的顶部有一个。还有一个使用PrepAndExpectedTestCase的完整示例。

总体思路是:

final IDatabaseTester databaseTester = new xxxx();
final IDatabaseConnection dbUnitConnection = databaseTester.getConnection();
final DatabaseConfig databaseConfig = dbUnitConnection.getConfig();
config.setProperty(DatabaseConfig.FEATURE_QUALIFIED_TABLE_NAMES, true);

下面是我对这个问题的解决方案,以注释的形式:

@DBUnit(schema = "test", qualifiedTableNames=true, dataTypeFactoryClass = MySqlDataTypeFactory.class, metaDataHandler= MySqlMetadataHandler.class )

你需要指定模式,也dataTypeFactoryClass和metaDataHandler,如果你有MariaDB的问题…

相关内容

  • 没有找到相关文章

最新更新