База данных не удаляется с помощью hibernate3-maven-plugin - PullRequest
0 голосов
/ 27 декабря 2011

Я использую плагин 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>

Мой hibernate 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 = create-drop, который, согласно документации, должен сбрасывать БД во время закрытия 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

(в настоящее время у меня есть только две сущности, поэтому это кажется подходящим)

Я не уверен, куда идти отсюда.Любая помощь будет оценена.

1 Ответ

0 голосов
/ 29 декабря 2011

Я получил функциональное решение, добавив <drop>true</drop> в раздел componentProperties конфигурации плагина.

...