这怎么可能发生。
不是liquibase应该为自己创建这个表...
这是为单元测试而创建的内存数据库。
public void setUp(String contexts) { try { ResourceAccessor resourceAccessor = new FileSystemResourceAccessor(); Class.forName("org.hsqldb.jdbcDriver"); holdingConnection = getConnectionImpl(); HsqlConnection hsconn = new HsqlConnection(holdingConnection); liquibase = new Liquibase(CHANGE_LOG, resourceAccessor, hsconn); liquibase.dropAll(); liquibase.update(contexts); hsconn.close(); } catch (Exception ex) { LOG.error("Error during database initialization", ex); throw new RuntimeException("Error during database initialization", ex); } } private Connection getConnectionImpl() throws SQLException { return DriverManager.getConnection(CONNECTION_STRING, USER_NAME, PASSWORD); }
与hsqldb示例相同
stacktrace:
2014-06-15 21:50:34,195 [DEBUG] [PropertySourcesPropertyResolver,getProperty(),103] - Could not find key 'spring.liveBeansView.mbeanDomain' in any property source. Returning [null] 2014-06-15 21:50:34,195 [DEBUG] [CacheAwareContextLoaderDelegate,loadContext(),93] - Storing ApplicationContext in cache under key [[MergedContextConfiguration@5879ff89 testClass = SampleUnitTest, locations = '{}', classes = '{class context.RepositoryContextConfig, class context.repoConfig}', contextInitializerClasses = '[]', activeProfiles = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]]. 2014-06-15 21:50:34,198 [DEBUG] [AbstractBeanFactory,doGetBean(),249] - Returning cached instance of singleton bean 'org.springframework.transaction.config.internalTransactionAdvisor' INFO 21:50 15/06/14: liquibase: Successfully acquired change log lock INFO 21:50 15/06/14: liquibase: Dropping Database Objects in schema: PUBLIC.PUBLIC INFO 21:50 15/06/14: liquibase: Creating database history table with name: PUBLIC.DATABASECHANGELOG INFO 21:50 15/06/14: liquibase: Successfully released change log lock 2014-06-15 21:51:17,842 [ERROR] [HsqlDatabase,setUp(),41] - Error during database initialization liquibase.exception.LockException: liquibase.exception.UnexpectedLiquibaseException: liquibase.exception.DatabaseException: Error executing SQL select count(*) from PUBLIC.DATABASECHANGELOGLOCK: user lacks privilege or object not found: DATABASECHANGELOGLOCK at liquibase.lockservice.StandardLockService.acquireLock(StandardLockService.java:214) at liquibase.lockservice.StandardLockService.waitForLock(StandardLockService.java:153) at liquibase.Liquibase.update(Liquibase.java:182) at liquibase.Liquibase.update(Liquibase.java:174) at context.HsqlDatabase.setUp(HsqlDatabase.java:38) at context.SampleUnitTest.onlyOnce(SampleUnitTest.java:19) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:233) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:87) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:176) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) Caused by: liquibase.exception.UnexpectedLiquibaseException: liquibase.exception.DatabaseException: Error executing SQL select count(*) from PUBLIC.DATABASECHANGELOGLOCK: user lacks privilege or object not found: DATABASECHANGELOGLOCK at liquibase.lockservice.StandardLockService.isDatabaseChangeLogLockTableInitialized(StandardLockService.java:121) at liquibase.lockservice.StandardLockService.init(StandardLockService.java:95) at liquibase.lockservice.StandardLockService.acquireLock(StandardLockService.java:187)
答案 0 :(得分:0)
hsqldb上的错误通常表示该表不存在。如果在检查后删除databasechangelog表,则“存在databasechangelog表存在”缓存机制可能会变得不正确。
在即将发布的liquibase 3.3版本中有一个修复程序,但是现在如果你在清除数据库的地方添加ChangeLogHistoryServiceFactory.getInstance().reset()
它应该解决问题。
答案 1 :(得分:0)
我相信当您的连接关闭或无效时,可能会发生此错误。
将Hsqldb-2.3.2与连接池(如dbcp)和validationQuery一起使用时,我遇到了同样的错误。一旦validationQuery使连接失效,就会在下一次数据库访问时抛出错误。
由于您在测试中,这不是您的问题,但您可以调试连接,看看它是否在出错时打开。