gpt4 book ai didi

HSQLDB 对象名称已存在

转载 作者:行者123 更新时间:2023-12-04 08:55:49 26 4
gpt4 key购买 nike

我正在尝试使用 2.2.9、Hibernate 3.6.9 和 Spring 3.1.2 版本设置 HSQL 数据库进行测试。我们一直在使用本地 postgresql 数据库,但正在转换以进行测试。我有 40-50 个测试类,总共有 200 多个测试。如果从 Eclipse 单独运行,每个测试类都可以正常工作。当我使用 Maven 编译和测试所有东西时,我有测试错误。在某些时候,它似乎试图再次运行我的 init.sql 脚本并再次创建表。我把这个作为我的最终原因:

Caused by: org.hsqldb.HsqlException: object name already exists: DUAL_ASSET_ASSETID_SEQ
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.SchemaObjectSet.checkAdd(Unknown Source)
at org.hsqldb.SchemaManager.checkSchemaObjectNotExists(Unknown Source)
at org.hsqldb.StatementSchema.setOrCheckObjectName(Unknown Source)
at org.hsqldb.StatementSchema.getResult(Unknown Source)
at org.hsqldb.StatementSchema.execute(Unknown Source)
at org.hsqldb.Session.executeCompiledStatement(Unknown Source)
at org.hsqldb.Session.executeDirectStatement(Unknown Source)
at org.hsqldb.Session.execute(Unknown Source) ... 52 more

我在创建该表时尝试使用“IF NOT EXISTS”,但是当我去创建序列时,我遇到了同样的错误。所以它试图做的不仅仅是一张表,而且我不能在 CREATE SEQUENCE 语句上使用“IF NOT EXISTS”,所以我被困在那里。

我的数据似乎再次加载有什么原因吗?我也偶尔收到此错误:
2012-10-16 10:55:48,489 [Thread-0] WARN
org.springframework.jdbc.datasource.embedded.HsqlEmbeddedDatabaseConfigurer:shutdown:46 - Could not shutdown embedded database java.sql.SQLException: Database lock acquisition failure: attempt to connect while db opening /closing
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCConnection.<init>(Unknown Source)
at org.hsqldb.jdbc.JDBCDriver.getConnection(Unknown Source)
at org.hsqldb.jdbc.JDBCDriver.connect(Unknown Source)
at org.springframework.jdbc.datasource.SimpleDriverDataSource.getConnectionFromDriver(SimpleDriverDataSource.java:140)
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:149)
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:119)
at org.springframework.jdbc.datasource.embedded.AbstractEmbeddedDatabaseConfigurer.shutdown(AbstractEmbeddedDatabaseConfigurer.java:40)
at org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactory.shutdownDatabase(EmbeddedDatabaseFactory.java:152)
at org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactoryBean.destroy(EmbeddedDatabaseFactoryBean.java:65)
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:211)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:498)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:474)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:442)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1071)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1045)
at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:963) Caused by: org.hsqldb.HsqlException: Database lock acquisition failure: attempt to connect while db opening /closing at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.DatabaseManager.getDatabase(Unknown Source)
at org.hsqldb.DatabaseManager.newSession(Unknown Source) ... 16 more

最佳答案

当前版本的 HSQLDB 允许 CREATE SEQUENCE IF NOT EXISTS 语句。

或者,对于测试,您可以在创建任何对象之前简单地删除 PUBLIC 模式的全部内容。

DROP SCHEMA PUBLIC CASCADE

关于HSQLDB 对象名称已存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12918407/

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