Maven + Spring + Hibernate:hibernate3-maven-plugin hbm2ddl由于原因失败“由......引发:java.lang.NullPointerException” [英] Maven + Spring + Hibernate: hibernate3-maven-plugin hbm2ddl fails for reason "Caused by: java.lang.NullPointerException"

查看:123
本文介绍了Maven + Spring + Hibernate:hibernate3-maven-plugin hbm2ddl由于原因失败“由......引发:java.lang.NullPointerException”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于目前在Spring中缺少对Hibernate 4的支持,所以我不得不将Hibernate从版本4降级到版本3(具体的3.3.2.GA),现在,当它试图生成模式时,该项目无法构建与hbm2ddl。这个错误太模糊了,而且谷歌并没有多少收获。



这是我的pom.xml:

 <?xml version =1.0encoding =UTF-8?> 
< project xmlns =http://maven.apache.org/POM/4.0.0
xmlns:xsi =http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation =
http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0的.xsd>
< modelVersion> 4.0.0< / modelVersion>

< groupId> com.example< / groupId>
< artifactId>示例< / artifactId>
< version> 1.0-SNAPSHOT< / version>
< name> Spring + Hibernate示例< / name>
<包装> jar< / packaging>

<属性>
< project.build.sourceEncoding> UTF-8< /project.build.sourceEncoding>
< spring.version> 3.1.2.RELEASE< /spring.version>
< hibernate.version> 3.3.2.GA< /hibernate.version>
< java.version> 1.6< /java.version>
< / properties>

< build>
< extensions>
< extension>
< groupId> org.hsqldb< / groupId>
< artifactId> hsqldb< / artifactId>
< version> 2.0.0< / version>
< / extension>
< extension>
< groupId> log4j< / groupId>
< artifactId> log4j< / artifactId>
< version> 1.2.17< / version>
< / extension>
< / extensions>
< plugins>
< plugin>
< groupId> org.apache.maven.plugins< / groupId>
< artifactId> maven-compiler-plugin< / artifactId>
< version> 2.0.2< / version>
<配置>
< source> $ {java.version}< / source>
< target> $ {java.version}< / target>
< / configuration>
< / plugin>
< plugin>
<! - 运行mvn hibernate3:hbm2ddl生成模式 - >
< groupId> org.codehaus.mojo< / groupId>
< artifactId> hibernate3-maven-plugin< / artifactId>
< version> 3.0< / version>

< executions>
<执行>
< id> generate-ddl< / id>
<阶段>程序类< /阶段>
<目标>
< goal> hbm2ddl< / goal>
< /目标>
< /执行>
< /执行次数>

<配置>
< annotationConfiguration configurationfile =hibernate.cfg.xml/>

< hbm2ddl export =falsecreate =trueupdate =true
format =formatoutputfilename =schemaDiff.ddl/>

< / hibernatetool>
< / configuration>

< / plugin>
< / plugins>
< / build>

<依赖关系>
<! - 控制反转:Spring依赖关系 - >
< dependency>
< groupId> org.springframework< / groupId>
< artifactId> spring-context< / artifactId>
< version> $ {spring.version}< / version>
<排除项>
<! - 排除有问题的commons-logging - >
<排除>
< groupId> commons-logging< / groupId>
< artifactId> commons-logging< / artifactId>
< /排除>
< /排除>
< /依赖关系>
< dependency>
< groupId> org.springframework< / groupId>
< artifactId> spring-core< / artifactId>
< version> $ {spring.version}< / version>
< /依赖关系>
< dependency>
< groupId> org.springframework< / groupId>
< artifactId> spring-orm< / artifactId>
< version> $ {spring.version}< / version>
< /依赖关系>
< dependency>
< groupId> commons-dbcp< / groupId>
< artifactId> commons-dbcp< / artifactId>
< version> 1.4< / version>
< /依赖关系>

<! - 对象关系映射:Hibernate - >
< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-core< / artifactId>
< version> $ {hibernate.version}< / version>
< /依赖关系>
< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-entitymanager< / artifactId>
< version> $ {hibernate.version}< / version>
< /依赖关系>
< dependency>
< groupId> javax.transaction< / groupId>
< artifactId> jta< / artifactId>
< version> 1.1< / version>
< /依赖关系>
< dependency>
< groupId> org.hibernate.javax.persistence< / groupId>
< artifactId> hibernate-jpa-2.0-api< / artifactId>
< version> 1.0.1.Final< / version>
< /依赖关系>

<! - Hibernate Annotations Dependencies - >
< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-annotations< / artifactId>
< version> 3.5.6-最终< / version>
< /依赖关系>
< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-commons-annotations< / artifactId>
< version> 3.3.0.ga< / version>
< /依赖关系>

<! - 数据库:HSQLDB - >
< dependency>
< groupId> org.hsqldb< / groupId>
< artifactId> hsqldb< / artifactId>
< version> 2.0.0< / version>
< /依赖关系>

<! - 连接池:C3P0 - >
< dependency>
< groupId> c3p0< / groupId>
< artifactId> c3p0< / artifactId>
< version> 0.9.1.2< / version>
< /依赖关系>

<! - 二级缓存:Ehcache - >
< dependency>
< groupId> ehcache< / groupId>
< artifactId> ehcache< / artifactId>
< version> 1.2.3< / version>
< /依赖关系>

<! - 记录:SLF4j& Log4J - >
< dependency>
< groupId> org.slf4j< / groupId>
< artifactId> jcl-over-slf4j< / artifactId>
< version> 1.6.6< / version>
< scope>运行时< / scope>
< /依赖关系>
< dependency>
< groupId> org.slf4j< / groupId>
< artifactId> slf4j-api< / artifactId>
< version> 1.6.6< / version>
< scope>运行时< / scope>
< /依赖关系>
< dependency>
< groupId> org.slf4j< / groupId>
< artifactId> slf4j-log4j12< / artifactId>
< version> 1.6.6< / version>
< scope>运行时< / scope>
< /依赖关系>
< dependency>
< groupId> log4j< / groupId>
< artifactId> log4j< / artifactId>
< version> 1.2.17< / version>
< scope>运行时< / scope>
< /依赖关系>

<! - Testing:JUnit - >
< dependency>
< groupId> junit< / groupId>
< artifactId> junit< / artifactId>
< version> 4.10< / version>
< /依赖关系>

<! - Testing:Spring - >
< dependency>
< groupId> org.springframework< / groupId>
< artifactId> spring-test< / artifactId>
< version> $ {spring.version}< / version>
< /依赖关系>

< /依赖关系>

< / project>

跑步

  mvn hibernate3:hbm2ddl 

无法与$ / b>

  [错误]无法执行目标org.codehaus.mojo:hibernate3-maven-plugin:3.0:hbm2ddl 
(default-cli)关于项目示例:创建AntRun任务时发生错误。
NullPointerException - > [帮助1]

完整的堆栈跟踪为:

  [错误]无法执行目标org.codehaus.mojo:hibernate3-maven-plugin:3.0:hbm2ddl(default-cli)关于项目示例:创建AntRun任务。 NullPointerException  - > [Help 1] 
org.apache.maven.lifecycle.LifecycleExecutionException:无法执行目标项目示例中的org.codehaus.mojo:hibernate3-maven-plugin:3.0:hbm2ddl(default-cli):出现错误创建AntRun任务。
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
在org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
在org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
在org.apache.maven .cli.MavenCli.doMain(MavenCli.java:
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect。 NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
在org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
导致:org.apache.maven.plugin.MojoExecutionException:创建AntRun任务时发生错误。
at org.codehaus.mojo.hibernate3.AbstractHibernateMojo.execute(AbstractHibernateMojo.java:84)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
在org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
... 19 more
引起:java.lang.NullPointerException $ b $ org.codehaus .plexus.configuration.DefaultPlexusConfiguration.add(DefaultPlexusConfiguration.java:174)
位于org.codehaus.plexus.configuration.DefaultPlexusConfiguration.addChild(DefaultPlexusConfiguration.java:150)
位于org.codehaus.mojo.hibernate3 .util.PlexusConfigurationUtils.setHibernateConfiguration(PlexusConfigurationUtils.java:289)
at org.codehaus.mojo.hibernate3.util.PlexusConfigurationUtils.parseHibernateTool(PlexusConfigurationUtils.java:67)
at org.codehaus.mojo.hibernate3 .AbstractHibernateToolMojo.getConfiguration(AbstractHibernateToolMojo.java:60)$ or $ $ b $ org.code haus.mojo.hibernate3.AbstractHibernateMojo.execute(AbstractHibernateMojo.java:76)
... 21 more

希望有人能对此有所阐述!

解决方案

我在尝试使maven引导时遇到同样的问题来自hibernate模型的数据库(问题描述在生成数据库模式(Hibernate )

我的hbm2ddl在以下版本的组合中工作得很好:
Hibernate(runtime):4.1.7 .Final
hibernate3-maven-plugin:3.6.10.Final,指定的插件版本2.2
hibernate3-maven-plugin的hibernate-validator依赖项:4.2.0.Final

在pom的相关部分之下:

版本:

 <性状> 

< org.hibernate.version> 4.1.7.Final< /org.hibernate.version>
< hibernate.maven.plugin.version> 3.6.10.Final< /hibernate.maven.plugin.version>

< / properties>

hibernate3-maven-plugin的定义:

 <建立> 
< plugins>
< plugin>
< groupId> org.codehaus.mojo< / groupId>
< artifactId> hibernate3-maven-plugin< / artifactId>
< version> 2.2< / version>
<配置>
<组件>
< component>
<名称> hbm2ddl< / name>
< implementation> jpa配置< / implementation>
< / component>

< /组件>

< componentProperties>
< outputfilename> schema.ddl< / outputfilename>
< create> true< / create>
<导出> false< /导出>
< format> true< / format>
< drop> false< / drop>
< jdk5> true< / jdk5>
< propertyfile> target / test-classes / application.properties< / propertyfile>
< skip> $ {skipTests}< / skip>
< / componentProperties>
< / configuration>
<执行次数>
<执行>
<阶段>程序类< /阶段>
<目标>
< goal> hbm2ddl< / goal>
< /目标>
< /执行>
< /执行次数>
<依赖关系>
< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-entitymanager< / artifactId>
< version> $ {hibernate.maven.plugin.version}< / version>
<排除项>
<排除>
< groupId> cglib< / groupId>
< artifactId> cglib< / artifactId>
< /排除>
<排除>
< groupId> commons-logging< / groupId>
< artifactId> commons-logging< / artifactId>
< /排除>
< /排除>
< /依赖关系>
< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-core< / artifactId>
< version> $ {hibernate.maven.plugin.version}< / version>
<排除项>
<排除>
< groupId> cglib< / groupId>
< artifactId> cglib< / artifactId>
< /排除>
<排除>
< groupId> commons-logging< / groupId>
< artifactId> commons-logging< / artifactId>
< /排除>
< /排除>
< /依赖关系>
< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-validator< / artifactId>
< version> 4.2.0.Final< / version>
< /依赖关系>

< /依赖关系>
< / plugin>

< / plugins>
< / build>

运行时依赖关系:

 <依赖性> 

< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-core< / artifactId>
< version> $ {org.hibernate.version}< / version>
< /依赖关系>

< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-entitymanager< / artifactId>
< version> $ {org.hibernate.version}< / version>
< /依赖关系>
< /依赖关系>

我希望这有助于您。


I had to downgrade Hibernate from version 4 to version 3 (3.3.2.GA to be specific), due to current lack of support for Hibernate 4 within Spring, and now the project fails to build when it attempts to generate schema with hbm2ddl. The error is too vague, and Google-ing it hasn't yielded much.

Here's my pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="
         http://maven.apache.org/POM/4.0.0
         http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>example</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>Spring + Hibernate Example</name>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <spring.version>3.1.2.RELEASE</spring.version>
        <hibernate.version>3.3.2.GA</hibernate.version>
        <java.version>1.6</java.version>
    </properties>

    <build>
        <extensions>
            <extension>
                <groupId>org.hsqldb</groupId>
                <artifactId>hsqldb</artifactId>
                <version>2.0.0</version>
            </extension>
            <extension>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.17</version>
            </extension>
        </extensions>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.0.2</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <!-- Run "mvn hibernate3:hbm2ddl" to generate schema -->
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>hibernate3-maven-plugin</artifactId>
                <version>3.0</version>

                <executions>
                    <execution>
                        <id>generate-ddl</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>hbm2ddl</goal>
                        </goals>
                    </execution>
                </executions>

                <configuration>
                    <hibernatetool destdir="${project.build.directory}/generated">
                        <annotationConfiguration configurationfile="hibernate.cfg.xml"/>

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

                    </hibernatetool>
                </configuration>

            </plugin>
        </plugins>
    </build>

    <dependencies>
        <!-- Inversion of Control: Spring Dependencies -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
            <exclusions>
                <!-- Exclude the problematic commons-logging -->
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>

        <!-- Object Relational Mapping: Hibernate -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.transaction</groupId>
            <artifactId>jta</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>1.0.1.Final</version>
        </dependency>

        <!-- Hibernate Annotations Dependencies -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.5.6-Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-commons-annotations</artifactId>
            <version>3.3.0.ga</version>
        </dependency>

        <!-- Database: HSQLDB -->
        <dependency>
            <groupId>org.hsqldb</groupId>
            <artifactId>hsqldb</artifactId>
            <version>2.0.0</version>
        </dependency>

        <!-- Connection Pool: C3P0 -->
        <dependency>
            <groupId>c3p0</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.1.2</version>
        </dependency>

        <!-- Second-level caching: Ehcache -->
        <dependency>
            <groupId>ehcache</groupId>
            <artifactId>ehcache</artifactId>
            <version>1.2.3</version>
        </dependency>

        <!-- Logging: SLF4j & Log4J -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>1.6.6</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.6</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.6.6</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
            <scope>runtime</scope>
        </dependency>

        <!-- Testing: JUnit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
        </dependency>

        <!-- Testing: Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
        </dependency>

    </dependencies>

</project>

Running

mvn hibernate3:hbm2ddl

fails with

[ERROR] Failed to execute goal org.codehaus.mojo:hibernate3-maven-plugin:3.0:hbm2ddl
(default-cli) on project example: There was an error creating the AntRun task.
NullPointerException -> [Help 1]

The full stack trace is:

[ERROR] Failed to execute goal org.codehaus.mojo:hibernate3-maven-plugin:3.0:hbm2ddl (default-cli) on project example: 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 (default-cli) on project example: There was an error creating the AntRun task.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: There was an error creating the AntRun task.
    at org.codehaus.mojo.hibernate3.AbstractHibernateMojo.execute(AbstractHibernateMojo.java:84)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    ... 19 more
Caused by: java.lang.NullPointerException
    at org.codehaus.plexus.configuration.DefaultPlexusConfiguration.add(DefaultPlexusConfiguration.java:174)
    at org.codehaus.plexus.configuration.DefaultPlexusConfiguration.addChild(DefaultPlexusConfiguration.java:150)
    at org.codehaus.mojo.hibernate3.util.PlexusConfigurationUtils.setHibernateConfiguration(PlexusConfigurationUtils.java:289)
    at org.codehaus.mojo.hibernate3.util.PlexusConfigurationUtils.parseHibernateTool(PlexusConfigurationUtils.java:67)
    at org.codehaus.mojo.hibernate3.AbstractHibernateToolMojo.getConfiguration(AbstractHibernateToolMojo.java:60)
    at org.codehaus.mojo.hibernate3.AbstractHibernateMojo.execute(AbstractHibernateMojo.java:76)
    ... 21 more

Hopefully someone can shed some light on this!

解决方案

I faced the same problem while trying to make maven bootstrap a database from a hibernate model (issue described in Generate database schema (Hibernate) on maven test).

I got hbm2ddl working quite well with the following combination of versions: Hibernate (runtime): 4.1.7.Final hibernate3-maven-plugin: 3.6.10.Final, specified plugin version 2.2 hibernate3-maven-plugin's hibernate-validator dependency: 4.2.0.Final

Below the relevant parts of the pom:

Versions:

<properties>

    <org.hibernate.version>4.1.7.Final</org.hibernate.version>
    <hibernate.maven.plugin.version>3.6.10.Final</hibernate.maven.plugin.version>

</properties>

hibernate3-maven-plugin's definition:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>hibernate3-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <components>
                    <component>
                        <name>hbm2ddl</name>
                        <implementation>jpaconfiguration</implementation>
                    </component>

                </components>

                <componentProperties>
                    <outputfilename>schema.ddl</outputfilename>
                    <create>true</create>
                    <export>false</export>
                    <format>true</format>
                    <drop>false</drop>
                    <jdk5>true</jdk5>
                    <propertyfile>target/test-classes/application.properties</propertyfile>
                    <skip>${skipTests}</skip>
                </componentProperties>
            </configuration>
            <executions>
                <execution>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>hbm2ddl</goal>
                    </goals>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>org.hibernate</groupId>
                    <artifactId>hibernate-entitymanager</artifactId>
                    <version>${hibernate.maven.plugin.version}</version>
                    <exclusions>
                        <exclusion>
                            <groupId>cglib</groupId>
                            <artifactId>cglib</artifactId>
                        </exclusion>
                        <exclusion>
                            <groupId>commons-logging</groupId>
                            <artifactId>commons-logging</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
                <dependency>
                    <groupId>org.hibernate</groupId>
                    <artifactId>hibernate-core</artifactId>
                    <version>${hibernate.maven.plugin.version}</version>
                    <exclusions>
                        <exclusion>
                            <groupId>cglib</groupId>
                            <artifactId>cglib</artifactId>
                        </exclusion>
                        <exclusion>
                            <groupId>commons-logging</groupId>
                            <artifactId>commons-logging</artifactId>
                        </exclusion>
                    </exclusions>
                </dependency>
                <dependency>
                    <groupId>org.hibernate</groupId>
                    <artifactId>hibernate-validator</artifactId>
                    <version>4.2.0.Final</version>
                </dependency>

            </dependencies>
        </plugin>

    </plugins>
</build>

Runtime dependencies:

<dependencies>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>${org.hibernate.version}</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>${org.hibernate.version}</version>
    </dependency>
</dependencies>

I hope this helps.

这篇关于Maven + Spring + Hibernate:hibernate3-maven-plugin hbm2ddl由于原因失败“由......引发:java.lang.NullPointerException”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆