divinespear / jpa-schema-maven-plugin

Maven plugin for generate database schema or DDL scripts from JPA entities
http://divinespear.github.io/jpa-schema-maven-plugin
Apache License 2.0
21 stars 19 forks source link

NullPointerException #19

Open delenius opened 8 years ago

delenius commented 8 years ago

I get an NPE when running mvn jpa-schema:generate -e -X:

[ERROR] Failed to execute goal io.github.divinespear:jpa-schema-maven-plugin:0.1.12:generate (default-cli) on project sunflower-server: Error while running: NullPointerException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal io.github.divinespear:jpa-schema-maven-plugin:0.1.12:generate (default-cli) on project sunflower-server: Error while running
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
    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:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Error while running
    at io.github.divinespear.maven.plugin.JpaSchemaGeneratorMojo.execute(JpaSchemaGeneratorMojo.java:768)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    ... 20 more
Caused by: java.lang.NullPointerException
    at org.hibernate.engine.jdbc.dialect.internal.StandardDialectResolver.resolveDialect(StandardDialectResolver.java:156)
    at io.github.divinespear.maven.plugin.JpaSchemaGeneratorMojo.generate(JpaSchemaGeneratorMojo.java:586)
    at io.github.divinespear.maven.plugin.JpaSchemaGeneratorMojo.execute(JpaSchemaGeneratorMojo.java:766)
    ... 22 more

I have this in my pom.xml:

      <plugin>
          <groupId>io.github.divinespear</groupId>
          <artifactId>jpa-schema-maven-plugin</artifactId>
          <version>0.1.12</version>
          <configuration>
            <hibernate.dialect>org.hibernate.dialect.MySQL5Dialect</hibernate.dialect>
            <databaseMajorVersion>5</databaseMajorVersion>
            <databaseMinorVersion>1</databaseMinorVersion>
          </configuration>
          <executions>
              <!-- if you want auto-generate schema on lifecycle. default lifecycle is "process-classes". -->
          </executions>
          <dependencies>
              <!-- JDBC driver here (if you don't defined in dependencies) -->
          </dependencies>
      </plugin>

and elsewhere in pom.xml:

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.6</version>
    </dependency>
pillingworth commented 7 years ago

I had a similar issue. I avoided it by specifying the database name in the configuration. In my case for SQL server I added:

<databaseProductName>Microsoft SQL Server</databaseProductName>

pillingworth commented 7 years ago

This worked for me...

<plugin>
    <groupId>io.github.divinespear</groupId>
    <artifactId>jpa-schema-maven-plugin</artifactId>
    <version>0.2.1</version>
    <configuration>
        <hibernate.dialect>org.hibernate.dialect.SQLServer2012Dialect</hibernate.dialect>
        <databaseProductName>Microsoft SQL Server</databaseProductName>
        <databaseMajorVersion>11</databaseMajorVersion>
        <databaseMinorVersion>0</databaseMinorVersion>
        <vendor>hibernate</vendor>
        <packageToScan>c.s.n.s.entities</packageToScan>
        <scriptAction>create</scriptAction>
        <format>true</format>
     </configuration>                
    <dependencies>
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.1-api</artifactId>
            <version>1.0.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>5.0.12.Final</version>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
</plugin>