2011-12-27 59 views
0

我在运行测试之前使用hibernate3-maven-plugin生成我的模式,并且它正在成功创建模式,但未成功删除它。数据库不会因为hibernate3-maven-plugin而丢失

我的插件配置:

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>hibernate3-maven-plugin</artifactId> 
    <version>2.2</version> 
    <executions> 
     <execution> 
      <phase>process-test-classes</phase> 
      <goals> 
       <goal>hbm2ddl</goal> 
      </goals> 
     </execution> 
    </executions> 
    <configuration> 
     <components> 
      <component> 
       <name>hbm2ddl</name> 
       <implementation>annotationconfiguration</implementation> 
      </component> 
     </components> 
     <componentProperties> 
      <implementation>jpaconfiguration</implementation> 
      <persistenceunit>JpaPersistenceUnit</persistenceunit> 
      <configurationfile>src/test/resources/hibernate.cfg.xml</configurationfile> 
     </componentProperties> 
    </configuration> 
    <dependencies> 
     <dependency> 
      <groupId>mysql</groupId> 
      <artifactId>mysql-connector-java</artifactId> 
      <version>5.1.5</version> 
     </dependency> 
    </dependencies> 
</plugin> 

我的休眠XML:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE hibernate-configuration SYSTEM 
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> 
<hibernate-configuration> 
    <session-factory> 
     <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> 
     <property name="hibernate.connection.url">jdbc:mysql://localhost/db_test</property> 
     <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> 
     <property name="hibernate.connection.username">root</property> 
     <property name="hibernate.connection.password">root</property> 
     <property name="hibernate.connection.pool_size">1</property> 
     <property name="hibernate.show_sql">true</property> 
     <property name="hibernate.hbm2ddl.auto">create-drop</property> 
    </session-factory> 
</hibernate-configuration> 

正如你所看到的,我使用hbm2ddl.auto =创造降,该文档状态应该放弃的db在SessionFactory关闭时。

然而,当我跑我的测试,第二次,我看到以下错误:

[ERROR] Error #1: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'stations' already exists 
[ERROR] Error #1: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'track_scans' already exists 

(我现在只有两个实体,因此这似乎是恰当的)

我不是确定从哪里出发。任何帮助,将不胜感激。

回答

0

我最终通过将<drop>true</drop>添加到插件配置的componentProperties部分来获得功能性解决方案。

相关问题