ClassCastException when using Liquibase Facade


I am trying to invoke Liquibase through the Facade as described in by passing it a dataSource created by DBCP through Spring as follows,


I am using 2.0 RC1.

In my class, I am invoking Liquibase as follows,

// Create the database
ApplicationContext ctx = WebApplicationContextUtils
BasicDataSource dataSource = ((BasicDataSource) ctx

	Connection connection = DataSourceUtils

	// Create the database
	Liquibase liquibase = new Liquibase("db.xml",
			new ClassLoaderResourceAccessor(), DatabaseFactory
							(DatabaseConnection) connection));

The problem here is that when using DBCP, it becomes nigh on impossible to cast the connection to a DatabaseConnection and I get a ClassCastException.

I have tried using DriverManager to re-construct a datasource but it still fails noting that it just can’t cast whatever connection is returned by JDBC to DatabaseConnection. I can’t see a way to “create” a DatabaseConnection class in the documentation at all.

Creating another JNDI data source might work but it isn’t an option as I dont want to define 2 different datasources which our end users have to configure.

Any help from people who have experience or insight is appreciated.

The documentation hasn’t been updated with some of the changes made in 2.0 yet.

You can call “new JdbcConnection(conn)” to correctly wrap your connection object to pass to the facade.  I’ll probably create a constructor on liquibase.Liquibase to take a standard connection object as well.


Thanks Nathan! This was keeping me up for ages. I am happy to volunteer to update documentation if it helps as Liquibase is soon going to become a core necessity for our work.

Any help you could do would be greatly appreciated.  I set up the documentation as a wiki so it can be easily updated as people find errors or holes.