HSQLDB和Liquibase,表已经存在:DATABASECHANGELOGLOCK

时间:2014-06-14 11:43:04

标签: java maven integration-testing hsqldb liquibase

我正在尝试使用liquibase和HSQLDB实现单元测试。 一切正常。但出于某种原因,当liquibase尝试在数据库中应用更改日志时,我得到:

INFO 14:19 14/06/14:liquibase: Successfully acquired change log lock
INFO 14:19 14/06/14:liquibase: Creating database history table with name: PUBLIC.DATABASECHANGELOG
2014-06-14 14:19:03,923 [DEBUG] [NewPooledConnection,handleThrowable(),430] - com.mchange.v2.c3p0.impl.NewPooledConnection@281fb795 handling a throwable.
java.sql.SQLException: Table already exists: DATABASECHANGELOGLOCK in statement [CREATE TABLE PUBLIC.DATABASECHANGELOGLOCK]
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.jdbcStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.jdbcStatement.execute(Unknown Source)
at com.mchange.v2.c3p0.impl.NewProxyStatement.execute(NewProxyStatement.java:1006)

我无法理解为什么会发生这种情况。

上下文提出一次。而且我决不会在......之前看到该表格被创建。

HSQLDB也在内存中运行。所以有一个新的实例..

有什么想法吗? 这是我的上下文和maven插件配置":

repository.connectionString = jdbc:hsqldb:mem:testdb
repository.driver = org.hsqldb.jdbcDriver
repository.username = SA
repository.password = 
repository.hibernate.dialect = org.hibernate.dialect.H2Dialect
repository.hibernate.showSQL = true
repository.hibernate.onStartup = verify



public com.mchange.v2.c3p0.ComboPooledDataSource dataSource() throws PropertyVetoException {
    com.mchange.v2.c3p0.ComboPooledDataSource ds = new ComboPooledDataSource();
    ds.setDriverClass(REPOSITORY_DRIVER);
    ds.setJdbcUrl(REPOSITORY_CONNTION_STRING);
    ds.setUser(REPOSITORY_USERNAME);
    ds.setPassword(REPOSITORY_PASSWORD);
    ds.setAcquireIncrement(5);
    ds.setIdleConnectionTestPeriod(60);
    ds.setMaxPoolSize(10);
    ds.setMaxStatements(50);
    ds.setMinPoolSize(5);
    return ds;
}
@Bean
@Autowired
public HibernateTransactionManager transactionManager(LocalSessionFactoryBean annotationSessionFactoryBean) {
    return new HibernateTransactionManager(annotationSessionFactoryBean.getObject());
}
@Bean
@Autowired
public LocalSessionFactoryBean sessionFactory(ComboPooledDataSource dataSource) {
    LocalSessionFactoryBean localSessionFactoryBean = new LocalSessionFactoryBean();
    localSessionFactoryBean.setDataSource(dataSource);
    localSessionFactoryBean.setPackagesToScan(new String[] { "X.Y.Z" });
    localSessionFactoryBean.setHibernateProperties(hibernateProperties());
    return localSessionFactoryBean;
}   
@Bean
@Autowired
public SpringLiquibase liquibae(ComboPooledDataSource dataSource){
    SpringLiquibase springLiquibase = new SpringLiquibase();
    springLiquibase.setDataSource(dataSource);
    springLiquibase.setContexts("dev,test");
    springLiquibase.setChangeLog("classpath:db/db.changelog-master.xml");   
    return springLiquibase;
}
private Properties hibernateProperties() {
    Properties hibernateProperties = new Properties();
    hibernateProperties.setProperty("dialect", REPOSITORY_HIBERNATE_DIALECT);
    hibernateProperties.setProperty("show_sql", REPOSITORY_HIBERNATE_SHOWSQL);
    hibernateProperties.setProperty("hibernate.hbm2ddl.auto", REPOSITORY_HIBERNATE_ONSTARTUP);
    return hibernateProperties;
}

行家:

 <plugin>
    <!-- current version -->
    <groupId>fr.avianey.mojo</groupId>
    <artifactId>hsqldb-maven-plugin</artifactId>
    <version>1.0.0</version>
    <!-- call start and stop -->
    <executions>
        <execution>
            <id>start-hsqldb</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>start</goal>
            </goals>
        </execution>
        <execution>
            <id>stop-hsqldb</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>stop</goal>
            </goals>
        </execution>
    </executions>
</plugin>  

0 个答案:

没有答案