小编典典

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

hibernate

我已经更新到了较新版本的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.

阅读 290

收藏
2020-06-20

共1个答案

小编典典

配置方式已更改为直接使用ant
hibernate工具插件。因此,配置与ant插件格式完全相同,而无需额外的taskDef例如jpaconfiguration。有关更多信息,请参见hibernate
ant工具参考文档:http
:
//docs.jboss.org/tools/3.3.0.Final/en/hibernatetools/html_single/index.html#d0e4651。

对于具有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>

出现故障时 ,将使用“ target / antrun / build-main.xml”文件配置hibernate工具。对于上面的示例,该示例如下所示:

<?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>
2020-06-20