2012-11-20 67 views

回答

3

如果你使用Spring,你可以使用它的JDBC實用工具填充數據庫:

<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" 
    xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"> 

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

    <bean class="org.springframework.jdbc.datasource.init.DataSourceInitializer" depends-on="sessionFactory"> 
     <property name="databasePopulator" ref="resourceDatabasePopulator" /> 
     <property name="dataSource" ref="dataSource" /> 
    </bean> 

    <bean id="resourceDatabasePopulator" class="org.springframework.jdbc.datasource.init.ResourceDatabasePopulator"> 
     <property name="scripts"> 
      <array> 
       <value>classpath*:init-hibernate.sql</value> 
      </array> 
     </property> 
    </bean> 
</beans> 
+0

英雄的一天! – jorrebor