就像标题所说,我有一个项目spring+hibernate
到JPA
,而my persistence.xml
hbm2ddl.auto=create
只更新了数据库。显然很多人都有同样的问题。所以我现在的问题是我有一个import.sql,它加载系统用户等独特的。在运行程序之前手动清理数据库有点烦人。是否有任何解决方法在重新创建数据之前清除数据。谢谢
我的persistence.xml和context.xml如下所示:
<!--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" />