Database schema generation with Hibernate and Maven

Hi there,

I am trying to generate sql for my Vaadin project with Hibernate. So far, Eclipse has automatically updated the database, which gave me a good start to develop with Vaadin. But to have a healthy code lifecycle strategy, I want no automatic database updates but generated sql. I am trying to use
mvn hibernate3:hbm2ddl
but it gives errors.

Attached below:

  • maven error log
  • persistence.xml
  • pom.xml

Does anyone have an idea what the issue is? Or how do you generate your database changes?
Thanks for your help.



Failed to execute goal org.codehaus.mojo:hibernate3-maven-plugin:3.0:hbm2ddl (default-cli) on project test2: 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 test2: There was an error creating the AntRun task.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(
at org.apache.maven.DefaultMaven.doExecute(
at org.apache.maven.DefaultMaven.execute(
at org.apache.maven.cli.MavenCli.execute(
at org.apache.maven.cli.MavenCli.doMain(
at org.apache.maven.cli.MavenCli.main(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(
at org.codehaus.plexus.classworlds.launcher.Launcher.main(
Caused by: org.apache.maven.plugin.MojoExecutionException: There was an error creating the AntRun task.
at org.codehaus.mojo.hibernate3.AbstractHibernateMojo.execute(
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(
… 19 more
Caused by: java.lang.NullPointerException
at org.codehaus.plexus.configuration.DefaultPlexusConfiguration.add(
at org.codehaus.plexus.configuration.DefaultPlexusConfiguration.addChild(
at org.codehaus.mojo.hibernate3.util.PlexusConfigurationUtils.setHibernateConfiguration(
at org.codehaus.mojo.hibernate3.util.PlexusConfigurationUtils.parseHibernateTool(
at org.codehaus.mojo.hibernate3.AbstractHibernateToolMojo.getConfiguration(
at org.codehaus.mojo.hibernate3.AbstractHibernateMojo.execute(
… 21 more


<?xml version="1.0" encoding="UTF-8"?>

<persistence-unit name="local">
        <property name="hibernate.archive.autodetection" value="class" />
        <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
        <property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
        <property name="hibernate.connection.url" value="jdbc:postgresql://localhost:55641/test2" />
        <property name="hibernate.connection.username" value="..." />
        <property name="hibernate.connection.password" value="..." />
        <property name="hibernate.flushMode" value="FLUSH_AUTO" />          
  <property name="eclipselink.ddl-generation" value="create-or-extend-tables" />
  <property name="eclipselink.application-location" value="/sql" />
  <property name="eclipselink.create-ddl-jdbc-file-name" value="create.sql"/>
  <property name="eclipselink.drop-ddl-jdbc-file-name" value="drop.sql"/>
  <property name="eclipselink.ddl-generation.output-mode" value="sql-script"/>

pom.xml (extract):

                            <jpaconfiguration persistenceunit="local" />   
                            <hbm2ddl export="false" create="true"
                                update="true" format="true" outputfilename="${basedir}/.openshift/action_hooks/sql/resourcesschemaDiff.ddl" />             

I am using Vaadin 7.3.3 and a postgreSQL 9.3 database.

I forgot to mention that so far, the Eclipse JPA manager updated the database schema for me (
JPA Tools
- Generate Tables from Entities - Output Mode “Database”). However, the output mode “Sql-script” didn’t work and that’s why I tried to do it with Hibernate and Maven instead. It seemed to generate sql output but in the end the file didn’t exist:

Resource ‘/Swisscreate-20150203/createDDL.sql’ does not exist.

If you have an idea how to solve this issue, that would be great too!


What you want to create is the sql schema of your database with hibernate?

Yes. I have the annotated model classes and want to generate the sql queries needed to create/update the database schema. I don’t mind if it’s done with the Eclipse JPA Tools or with maven and Hibernate but neither of them works at the moment.

And why do you want the sql file for creating the schema manually?

You can do it using postgresql, can’t you?

Do you mean why I don’t want it to be executed on the database automatically? I want to execute it manually because I need to execute it on the dev/test/production databases separately.

I think you can do it with your hibernate.cfg.xml: select the database manually.

Thanks for your suggestion. I think you are saying I should let Eclipse upgrade my production database as well, right? I am afraid that is no option for me. I have a dev, test and production server with separated databases and I work with database upgrade and downgrade scripts between all the software versions. Do you know what I mean?

I get it. You can’t let Hibernate delete your database or upgrade itself…