A new topic, 'ClassCastException when using Liquibase Facade', has been made on a board you are watching.
You can see it at
http://liquibase.org/forum/index.php?topic=439.new#new
The text of the topic is shown below:
Hi,
I am trying to invoke Liquibase through the Facade as described in http://liquibase.jira.com/wiki/display/CONTRIB/Liquibase+Facade by passing it a dataSource created by DBCP through Spring as follows,
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
I am using 2.0 RC1.
In my class, I am invoking Liquibase as follows,
// Create the database
ApplicationContext ctx = WebApplicationContextUtils
.getWebApplicationContext(ServletActionContext
.getServletContext());
BasicDataSource dataSource = ((BasicDataSource) ctx
.getBean("dataSource"));
Connection connection = DataSourceUtils
.getTargetConnection(DataSourceUtils.getConnection(dataSource));
// Create the database
Liquibase liquibase = new Liquibase("db.xml",
new ClassLoaderResourceAccessor(), DatabaseFactory
.getInstance().findCorrectDatabaseImplementation(
(DatabaseConnection) connection));
liquibase.update(null);
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.
Unsubscribe to new topics from this board by clicking here: http://liquibase.org/forum/index.php?action=notifyboard;board=1.0
Regards,
The LiquiBase Community Forum Team.
|