0
我需要將我的Spring應用程序數據庫從MySql遷移到HSQL數據庫。我在我的xml文件中配置了hsql數據庫詳細信息,並且可以運行sql文件併成功連接到它。聽到這個問題是,當我重新啓動我的Tomcat服務器,新的數據庫正在創建和舊的數據庫被刪除。我正在查看我存儲在表格中的所有數據。我如何在戰爭部署時只爲HSQL創建一次數據庫,或者每次tomcat重新啓動時只創建一次。每次戰爭部署只創建一次hsqldb數據庫
聽到的是我的配置文件:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xsi:schemaLocation="
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/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-4.1.xsd">
<jdbc:embedded-database id="dbcpDataSource" type="HSQL">
<jdbc:script location="classpath:schema.sql"/>
</jdbc:embedded-database>
<tx:annotation-driven/>
<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
<property name="url" value="jdbc:hsqldb:mem:test"/>
<property name="username" value="sa"/>
<property name="password" value=""/>
<property name="maxActive" value="100000"/>
<property name="maxIdle" value="30"/>
<property name="maxWait" value="16000"/>
<property name="minIdle" value="0"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dbcpDataSource"/>
<property name="packagesToScan" value="com.design.model"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
</props>
</property>
<property name="exposeTransactionAwareSessionFactory"><value>false</value></property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
</beans>
我甚至使用內存配置要麼,我的要求是當外部服務器重新啓動,那麼我的數據庫也不應該創建。它只需要創建一次(即我們第一次部署戰爭) – Navyah
在這種情況下,在服務器中使用'file:'數據庫來保存數據。 – fredt
即使在使用文件後,它也會提供相同的問題。 –
Navyah