Невозможно сгенерировать hbm2ddl, используя hibernate3-maven-plugin-3.0 - PullRequest
12 голосов
/ 14 февраля 2012

Я обновился до новой версии hibernate3-maven-plugin. Я получаю следующую ошибку при попытке использовать плагин, упомянутый ниже.

Буду признателен за любые указания по решению этой проблемы.

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>hibernate3-maven-plugin</artifactId>
    <version>3.0</version>

    <executions>
        <execution>
            <id>create sql schema</id>
            <phase>process-test-resources</phase>
            <goals>
                <goal>hbm2ddl</goal>
            </goals>
            <configuration>
                <componentProperties>
                    <persistenceunit>${app.module}</persistenceunit>
                    <drop>false</drop>
                    <create>true</create>
                    <outputfilename>${app.sql}-create.sql</outputfilename>
                    <skip>${db.schema.gen.skip}</skip>
                </componentProperties>
            </configuration>
        </execution>

        <execution>
            <id>drop sql schema</id>
            <phase>process-test-resources</phase>
            <goals>
                <goal>hbm2ddl</goal>
            </goals>
            <configuration>
                <componentProperties>
                    <persistenceunit>${app.module}</persistenceunit>
                    <drop>true</drop>
                    <create>false</create>
                    <outputfilename>${app.sql}-drop.sql</outputfilename>
                    <skip>${db.schema.gen.skip}</skip>
                </componentProperties>
            </configuration>
        </execution>
    </executions>
</plugin>

[ERROR] Failed to execute goal org.codehaus.mojo:hibernate3-maven-plugin:3.0:hbm2ddl (create sql schema) on project sample: There was an error creating the AntRun task. NullPointerException -> [Help 1]org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.mojo:hibernate3-maven-plugin:3.0:hbm2ddl (create sql schema) on project framework: There was an error creating the AntRun task.

Ответы [ 3 ]

12 голосов
/ 17 февраля 2012

Способ настройки изменен на прямое использование плагина ant hibernate. Таким образом, конфигурация имеет тот же формат, что и плагин ant, без необходимости в дополнительном taskDef, например, для jpaconfiguration. См. Справочную документацию по инструменту hibernate: http://docs.jboss.org/tools/3.3.0.Final/en/hibernatetools/html_single/index.html#d0e4651 для получения дополнительной информации.

Для hbm2ddl с конфигурацией jpa вы можете использовать следующее:

<plugin>
    <!-- run "mvn hibernate3:hbm2ddl" to generate a schema -->
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>hibernate3-maven-plugin</artifactId>
    <version>3.0</version>

    <configuration>
        <hibernatetool>
            <jpaconfiguration persistenceunit="unitname" />

            <hbm2ddl export="false" create="true"
                update="true" format="true" outputfilename="schemaDiff.ddl" />

        </hibernatetool>
    </configuration>
</plugin>

При сбоях существует файл "target / antrun / build-main.xml", который настраивает инструменты гибернации. Для приведенного выше примера это выглядит следующим образом:

<?xml version="1.0" encoding="UTF-8" ?>
<project name="maven-antrun-" default="main"  >
<target name="main">
  <taskdef classname="org.hibernate.tool.ant.EnversHibernateToolTask" name="hibernatetool"/>
  <mkdir dir="/home/xxx/workspace/projectname/target/sql/hibernate3"/>
  <hibernatetool destdir="/home/xxx/workspace/projectname/target/sql/hibernate3">
    <jpaconfiguration persistenceunit="schemaDiff"/>
    <hbm2ddl update="true" export="false" outputfilename="schemaDiff.ddl" format=
"true" create="true"/>
  </hibernatetool>
</target>
</project>
3 голосов
/ 22 апреля 2012

Я заставил его работать следующим образом:

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>3.0</version>
<executions>
    <execution>
        <id>create-schema</id>
        <phase>process-test-resources</phase>
        <goals>
            <goal>run</goal>
        </goals>
        <configuration>
            <hibernatetool destdir="${project.basedir}">
                <classpath>
                    <path
                        location="${project.basedir}/src/main/resources/mappings/" />
                </classpath>
                <configuration
                    configurationfile="${project.basedir}/src/test/resources/hibernate.cfg.xml" />
                <hbm2ddl create="true" export="false"
                    drop="true" outputfilename="schema.sql"
                    format="true" console="false" />
            </hibernatetool>
        </configuration>
    </execution>
</executions>

Основная идея состоит в том, чтобы использовать цель 'run' и затем настроить hibernatetool для запуска нужных экспортеров.Таким образом, вы можете запустить несколько экспортеров за один раз, добавив больше конфигурации экспортеров внутри тега.Для получения дополнительной информации, смотрите здесь http://docs.jboss.org/tools/2.0.0.GA/hibernatetools/en/html_single/index.html и http://mojo.codehaus.org/hibernate3-maven-plugin/examples/run-multiple-goals.html. Мне понадобилось несколько часов, чтобы понять.Надеюсь, что помощь!

3 голосов
/ 02 марта 2012

У меня была такая же проблема, и в конце концов она была решена, следуя этому примеру (http://www.celinio.net/techblog/?p=1125) и указав hibernate deps только для плагина. Это потому, что в моем случае у меня есть отдельный объект домена модуль, в котором используется только JPA2 (без специальных ссылок гибернации), поэтому мне нужно было использовать deps для генерации DDL, не беспокоясь о том, как они влияют на зависимых элементов этого модуля.

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>hibernate3-maven-plugin</artifactId>
            <version>3.0</version>
            <configuration>
                <components>
                    <component>
                        <name>hbm2ddl</name>
                        <implementation>jpaconfiguration</implementation>
                    </component>
                </components>
                <hibernatetool>
                    <classpath>
                        <path location="${project.build.directory}/classes" />
                        <path location="${project.basedir}/src/main/resources/META-INF/" />
                    </classpath>
                    <jpaconfiguration persistenceunit="Configuration" />
                    <hbm2ddl create="true" export="false" drop="true"
                        outputfilename="configuration.sql" format="true" console="true" />
                </hibernatetool>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.hibernate.javax.persistence</groupId>
                    <artifactId>hibernate-jpa-2.0-api</artifactId>
                    <version>1.0.0.Final</version>
                </dependency>
                <dependency>
                    <groupId>org.hibernate</groupId>
                    <artifactId>hibernate-entitymanager</artifactId>
                    <version>3.6.7.Final</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>
...