首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用hibernate3-maven-plugin时数据库不会被删除

使用hibernate3-maven-plugin时数据库不会被删除
EN

Stack Overflow用户
提问于 2011-12-28 01:22:07
回答 1查看 523关注 0票数 0

在运行测试之前,我使用hibernate3-maven-plugin生成我的模式,它成功地创建了模式,但没有成功删除它。

我的插件配置:

代码语言:javascript
复制
<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>

我的hibernate xml:

代码语言:javascript
复制
<?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=create- drop,文档中指出它应该在SessionFactory关闭时删除数据库。

但是,当我第二次运行测试时,我看到以下错误:

代码语言:javascript
复制
[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

(我目前只有两个实体,所以这似乎是合适的)

我不知道下一步该怎么走。任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-12-29 22:18:22

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8647382

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档