Q:

Can I use HSQLDB for junit testing cloning a mySQL database

I am working on a spring webflow project and I am thinking can I use HSQLDB and not my mysql for junit testing?  
How can I clone my mysql database into HSQLDB

A:

If you are using spring 3.1 or greater you could use spring profiles to achieve this.  The default profile is loaded when no active profile is set.
<beans profile="dev">
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close"> 
        <property name="driverClass" value="org.hsqldb.jdbcDriver" />
        ...other datasource properties also create or drop db
    </bean>
</beans>
<beans profile="default">
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
    destroy-method="close"> 
        <property name="driverClass" value="com.mysql.jdbc.Driver" />
        ...other datasource properties
    </bean>
</beans>

In your unit test set the active profile by adding the annotation.
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:app-config.xml")
@ActiveProfiles("dev")
public class TransferServiceTest {

