如何将嵌入的H2内容写入磁盘文件?

时间:2013-04-10 21:24:19

标签: spring hibernate h2

我正在使用Spring 3.1和Hibernate 4以及最新的H2数据库(1.3.171)。我的应用程序最初是用MySQL配置编写的,但我也想在嵌入模式下使用H2。

我使用H2控制台创建表,应用程序可以使用数据库。但是当应用程序停止并重新启动时,数据库中没有任何内容。如果我使用控制台应用程序来查看数据库(而不是在应用程序运行时),我可以看到表,但它们没有条目。

这是sessionFactory配置:

    <!-- Hibernate SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
        <property name="annotatedClasses">
            <list>
                <value>com.hartzman.testapp.entity.User</value>
                <value>com.hartzman.testapp.entity.Order</value>
            </list>
        </property>
        <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop> 
            <prop key="hibernate.connection.driver_class">${jdbc.driverClassName}</prop>
            <prop key="hibernate.connection.url">${jdbc.url}</prop>
            <prop key="hibernate.connection.username">${jdbc.username}</prop>
            <prop key="hibernate.connection.password">${jdbc.password}</prop>
            <prop key="hibernate.connection.pool_size">1</prop>
            <prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>
            </props>
        </property>
    </bean>

  <bean id="transactionManager"
    class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />

我不想向H2发出SQL SHUTDOWN命令,因为我不想仅为H2更改代码 - 我希望能够切换出数据库。

所有帮助表示赞赏。

0 个答案:

没有答案