HSQLDB对象名称已经存在

我试图设置一个HSQL数据库进行测试,使用2.2.9版本,Hibernate 3.6.9和Spring 3.1.2。 我们一直在使用本地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
链接地址: http://www.djcxy.com/p/88631.html

上一篇: HSQLDB object name already exists

下一篇: Can Spring's Embedded HSQL database support the Sybase dialect?