1

就像标题所说的那样,我有一个项目,spring+hibernate它只更新数据库。显然很多人都有同样的问题。所以我现在的问题是我有一个 import.sql 加载系统用户等是唯一的。在运行程序之前手动清理数据库有点烦人。是否有任何解决方法可以在重新创建数据之前清除数据。感谢我的 persistence.xml 和 context.xml 如下所示:JPAmy persistence.xml hbm2ddl.auto=create

<!--persistence.xml-->
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="normal" transaction-type="RESOURCE_LOCAL">
  <provider>org.hibernate.ejb.HibernatePersistence</provider>
  </persistence-unit>
</persistence>


 <!--context.xml-->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="${mysql.jdbc.driverClassName}"/>
    <property name="url" value="${mysql.jdbc.url}"/>
    <property name="username" value="${mysql.jdbc.username}"/>
    <property name="password" value="${mysql.jdbc.password}"/>
</bean>

<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="persistenceUnitName" value="normal"/>

    <property name="jpaProperties">
        <props>
            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
            <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
            <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
            <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
            <prop key="org.hibernate.envers.audit_table_prefix"></prop>
            <prop key="org.hibernate.envers.audit_table_suffix">_AUDITED</prop>                
            <prop key="hibernate.connection.driverClassName">${mysql.jdbc.driverClassName}</prop>
            <prop key="hibernate.connection.url">${mysql.jdbc.url}</prop>
            <prop key="hibernate.connection.username">${mysql.jdbc.username}</prop>
            <prop key="hibernate.connection.password">${mysql.jdbc.password}</prop>
            <prop key="hibernate.connection.provider_class">${mysql.hibernate.connection.provider_class</prop>
            <prop key="hibernate.c3p0.max_size">${mysql.hibernate.c3p0.max_size}</prop>
            <prop key="hibernate.c3p0.min_size">${mysql.hibernate.c3p0.min_size}</prop>
            <prop key="hibernate.c3p0.acquire_increment">${mysql.hibernate.c3p0.acquire_increment}</prop>
            <prop key="hibernate.c3p0.idle_test_period">${mysql.hibernate.c3p0.idle_test_period}</prop>
            <prop key="hibernate.c3p0.max_statements">${mysql.hibernate.c3p0.max_statements}</prop>
            <prop key="hibernate.c3p0.timeout">${mysql.hibernate.c3p0.timeout}</prop>
        </props>
    </property>
</bean>

<bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
4

0 回答 0