Quantcast
Channel: Spring Community Forums - Data
Viewing all articles
Browse latest Browse all 297

Does jdbc:initialize-database work with NON embedded databases?

$
0
0
jdbc:initialize-database works great for my H2 database - but seems to be totally ignored for a connection pooled mysql one. Perhaps this feature only works with embedded databases? My context is as follows:
The test profile using h2 initialises fine but the dev profile using mysql never runs the scripts. Any help much appreciated. Cheers Kit


Code:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:jdbc="http://www.springframework.org/schema/jdbc"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xsi:schemaLocation="
                http://www.springframework.org/schema/beans
                http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                http://www.springframework.org/schema/jdbc
                http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
                http://www.springframework.org/schema/beans
                http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                http://www.springframework.org/schema/tx
                http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                http://www.springframework.org/schema/context
                http://www.springframework.org/schema/context/spring-context-3.0.xsd">
               
        <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <property name="sessionFactory"><ref local="sessionFactory"/></property>
        </bean>
       
        <tx:annotation-driven/>

        <context:component-scan base-package="uk.co.thirdbridge.core" />
       

        <bean id="accountDao" class="uk.co.thirdbridge.core.dao.AccountDaoImpl"/>               

        <beans profile="test">
       
                <jdbc:embedded-database id="dataSource" type="H2"/>

               
                <jdbc:initialize-database data-source="dataSource">
                        <jdbc:script location="classpath:sql/schema-h2.sql"/>
                        <jdbc:script location="classpath:sql/initial-data.sql"/>       
                </jdbc:initialize-database>                       
               
                <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
                        <property name="dataSource" ref="dataSource"/>
                        <property name="packagesToScan" value="uk.co.thirdbridge.core.domain"/>
                        <property name="hibernateProperties">
                                <props>
                                        <prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
                                        <prop key="hibernate.max_fetch_depth">3</prop>
                                        <prop key="hibernate.jdbc_fetch_depth">50</prop>
                                        <prop key="hibernate.jdbc_batch_size">10</prop>
                                        <prop key="hibernate.show_sql">true</prop>
                                </props>
                        </property>
                </bean>       
               
        </beans>
       
        <beans profile="development">
       
                <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
                    <property name="driverClass" value="com.mysql.jdbc.Driver" />
                    <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/thirdbridge" />
                    <property name="user" value="appserver_dev" />
                    <property name="password" value="password" />
                <!-- these are C3P0 properties -->
                <property name="acquireIncrement" value="2" />
                <property name="minPoolSize" value="5" />
                <property name="maxPoolSize" value="50" />
                <property name="maxIdleTime" value="1000"/>           
                </bean>       
               
                <jdbc:initialize-database data-source="dataSource" enabled="true">
                        <jdbc:script location="classpath:sql/schema-mysql.sql"/>
                        <jdbc:script location="classpath:sql/initial-data.sql"/>       
                </jdbc:initialize-database>                       
               
                <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
                        <property name="dataSource" ref="dataSource"/>
                        <property name="packagesToScan" value="uk.co.thirdbridge.core.domain"/>
                        <property name="hibernateProperties">
                                <props>
                                        <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                                        <prop key="hibernate.max_fetch_depth">3</prop>
                                        <prop key="hibernate.jdbc_fetch_depth">50</prop>
                                        <prop key="hibernate.jdbc_batch_size">10</prop>
                                        <prop key="hibernate.show_sql">true</prop>
                                </props>
                        </property>
                </bean>       
                               
        </beans>
       
</beans>


Viewing all articles
Browse latest Browse all 297

Trending Articles