[SPRING] Maven + Spring + Hibernate : hibernate3-maven-plugin hbm2ddl은 "원인 : java.lang.NullPointerException"이유로 실패합니다.
SPRINGMaven + Spring + Hibernate : hibernate3-maven-plugin hbm2ddl은 "원인 : java.lang.NullPointerException"이유로 실패합니다.
Spring 내에서 Hibernate 4에 대한 지원이 부족하여 Hibernate를 버전 4에서 버전 3 (3.3.2.GA)로 다운 그레이드해야했고, 이제는 hbm2ddl로 스키마를 생성하려고 시도 할 때 프로젝트가 빌드되지 않습니다. 오류는 너무 애매하고 Google이 많이 내놓지 않았습니다.
다음은 내 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>
달리는
mvn hibernate3:hbm2ddl
~으로 실패하다
[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]
전체 스택 추적은 다음과 같습니다.
[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
바라기를 누군가는 이것에 어떤 빛을 비울 수있다!
해결법
-
==============================
1.나는 maven 부트 스트랩을 최대 절전 모드 (maven 테스트에서 데이터베이스 스키마 (Hibernate) 생성에 설명 된 문제)에서 데이터베이스로 만들려고 할 때 동일한 문제에 직면했다.
나는 maven 부트 스트랩을 최대 절전 모드 (maven 테스트에서 데이터베이스 스키마 (Hibernate) 생성에 설명 된 문제)에서 데이터베이스로 만들려고 할 때 동일한 문제에 직면했다.
hbm2ddl 버전의 다음 조합을 사용하면 꽤 잘 작동합니다. 최대 절전 모드 (런타임) : 4.1.7. 최종 hibernate3-maven-plugin : 3.6.10. 최종 지정된 플러그인 버전 2.2 hibernate3-maven-plugin의 hibernate-validator 의존성 : 4.2.0. 최종
POM의 관련 부분 아래 :
버전 :
<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의 정의 :
<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>
런타임 의존성 :
<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>
이게 도움이 되길 바란다.
-
==============================
2.커다란 프로젝트 (250 개 이상의 엔티티)에서는 다음 pom.xml 마녀가 잘 작동하고 컴파일 단계에서 스키마를 생성합니다. 참고 : persistence.xml은 데이터베이스 언어를 지정합니다.
커다란 프로젝트 (250 개 이상의 엔티티)에서는 다음 pom.xml 마녀가 잘 작동하고 컴파일 단계에서 스키마를 생성합니다. 참고 : persistence.xml은 데이터베이스 언어를 지정합니다.
<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>test</groupId> <artifactId>jpa</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <!-- java EE (for annotations) --> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>6.0</version> <scope>provided</scope> </dependency> </dependencies> <build> <plugins> <!-- hibernate hmb2ddl plugin configuration --> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>hibernate3-maven-plugin</artifactId> <version>3.0</version> <executions> <execution> <id>generate.database.schema.from.ejb.annotation</id> <phase>compile</phase> <goals> <goal>run</goal> </goals> <configuration> <hibernatetool> <classpath><path location="src/main/java"/></classpath> <hbm2ddl console="false" export="false" update="false" drop="false" create="true" outputfilename="create.sql" format="false" haltonerror="true"> <jpaconfiguration persistenceunit="persist" /> </hbm2ddl> </hibernatetool> </configuration> </execution> </executions> <dependencies> <!-- hibernate tools --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>3.6.10.Final</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> <version>3.6.10.Final</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator</artifactId> <version>4.1.0.Final</version> </dependency> <dependency> <groupId>javassist</groupId> <artifactId>javassist</artifactId> <version>3.4.GA</version> </dependency> </dependencies> </plugin> </plugins> </build>
from https://stackoverflow.com/questions/13113115/maven-spring-hibernate-hibernate3-maven-plugin-hbm2ddl-fails-for-reason-ca by cc-by-sa and MIT license
'SPRING' 카테고리의 다른 글
[SPRING] 스프링 MVC 폼 유효성 검사가 작동하지 않습니다. (0) | 2019.04.12 |
---|---|
[SPRING] Grails 플러그인 빈의 오버라이드 메소드 (0) | 2019.04.12 |
[SPRING] Spring MVC 애플리케이션 - 세션 범위의 빈 값을 어떻게 설정 하는가? (0) | 2019.04.12 |
[SPRING] 글로벌 컨텍스트 컨텍스트가있는 Spring MVC 주석 : component-scan? (0) | 2019.04.12 |
[SPRING] Spring에서 여러 데이터베이스 초기화하기 (0) | 2019.04.12 |