Running Updates Programmatically Using JUnit

First off, thanks for such a great tool! I have successfully used LiquiBase with Maven to generate a database schema for a new project.

I am now looking to re-use some of the XML schema definitions in our unit tests. For production, we have a MySQL InnoDB database. For the unit tests, we want to use simple in-memory HSQLDB tables.

When I run the unit test, LiquiBase says that it ran the script (which creates a table) without error, but when I try to insert a record into the table using my application code, I get “java.sql.SQLException: user lacks privilege or object not found: USER”.

I changed the HSQLDB URL to use a file-based table for debugging and saw that the user table does not exist. I would sure appreciate it if you have any insight into what I might be doing wrong.

Here is the relevant code, change log XML, and output:

JDBCDataSource dataSource = new JDBCDataSource();
Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(dataSource.getConnection()));
Liquibase liquibase = new Liquibase(“user-db.xml”, new ClassLoaderResourceAccessor(), database);

<databaseChangeLog xmlns=“” xmlns:xsi=“” xsi:schemaLocation=“”>

INFO 1/7/10 11:15 AM:liquibase: Successfully acquired change log lock
INFO 1/7/10 11:15 AM:liquibase: Creating database history table with name: DATABASECHANGELOG
INFO 1/7/10 11:15 AM:liquibase: Reading from DATABASECHANGELOG
INFO 1/7/10 11:15 AM:liquibase: ChangeSet user-db.xml::1::dan ran successfully in 15ms
INFO 1/7/10 11:15 AM:liquibase: Successfully released change log lock

I think I figured it out. Apparently HSQLDB table names are case-sensitive. Even though I used all lowercase table names, the PreparedStatement capitalized the name. When I gave an uppercase table name to LiquiBase, the unit test passed.

I also included these lines I found in liquibase.integration.commandline.Main.doMigration():


They seemed to have no impact on the unit test.

Glad you found the problem.  The rollback should not do anything, since liquibase will commit the transaction after each changeset.