无法使用hibernate3-maven-plugin-3.0生成hbm2ddl

无法使用hibernate3-maven-plugin-3.0生成hbm2ddl,hibernate,hbm2ddl,Hibernate,Hbm2ddl,我已经更新到了hibernate3 maven插件的更新版本。我在尝试使用下面提到的插件时遇到以下错误 如果您能为解决此问题提供任何指导,我们将不胜感激 <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>hibernate3-maven-plugin</artifactId> <version>3.0</version>

我已经更新到了hibernate3 maven插件的更新版本。我在尝试使用下面提到的插件时遇到以下错误

如果您能为解决此问题提供任何指导,我们将不胜感激

<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.

org.codehaus.mojo
hibernate3 maven插件
3
创建sql模式
过程测试资源
hbm2ddl
${app.module}
假的
真的
${app.sql}-create.sql
${db.schema.gen.skip}
删除sql模式
过程测试资源
hbm2ddl
${app.module}
真的
假的
${app.sql}-drop.sql
${db.schema.gen.skip}
[错误]无法在项目示例上执行目标org.codehaus.mojo:hibernate3 maven插件:3.0:hbm2ddl(创建sql架构):创建AntRun任务时出错。NullPointerException->[Help 1]org.apache.maven.lifecycle.LifecycleeExecutionException:未能在project framework上执行目标org.codehaus.mojo:hibernate3 maven插件:3.0:hbm2ddl(创建sql架构):创建AntRun任务时出错。

配置方式改为直接使用ant hibernate工具插件。因此,配置与ant插件的格式完全相同,不需要额外的taskDef,例如JPA配置。有关更多信息,请参阅hibernate ant工具参考文档

对于带有jpa配置的hbm2ddl,您可以使用以下选项:

<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>
<?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>
<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>

org.codehaus.mojo
hibernate3 maven插件
3
失败时有一个“target/antrun/build main.xml”文件,用于配置hibernate工具。对于上面的示例,如下所示:

<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>
<?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>
<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>

我也遇到了同样的问题,最后通过以下示例()并单独为插件指定hibernate deps解决了这个问题。这是因为在我的例子中,我有一个单独的域对象模块,它只使用JPA2(没有特定的hibernate引用),所以我需要引入DEP来生成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>

org.codehaus.mojo
hibernate3 maven插件
3
hbm2ddl
JPA配置
org.hibernate.javax.persistence
hibernate-jpa-2.0-api
1.0.0.1决赛
org.hibernate
休眠实体管理器
3.6.7.最终版本

我已使其按如下方式工作:

<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>
<?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>
<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>

org.codehaus.mojo
和。

我花了几个小时才弄明白。希望对你有所帮助

这似乎仍然没有什么区别,我观察到了与以前相同的错误。相关的调试消息可以为解决此问题提供更多提示。只需在maven命令中添加“-X”或“-debug”。请粘贴target/antrun/build-main.xml文件的内容,这样我们就可以看到ant任务是如何配置的。请参阅我编辑的答案以获得第一次比较。在依赖项中添加hibernate-jpa-2.0-api:1.0.0.Final、hibernate entitymanager:3.6.8.Final、hibernate core:3.6.8.Final、hibernate validator:4.2.0.Final后,此解决方案对我有效