Hibernate Tools is a toolset for Hibernate3 implemented as an integrated suite of Eclipse plugins, together with a unified Ant task for integration into the build cycle.
Working with Maven you can use the hibernate3-maven-plugin. But this is (as the name states) only for Hibernate 3 and does not support Hibernate 4.
As reported by Thomas Letsch  the Hibernate tools for Hibernate 4.x is not yet finished, and the obvious solution is to just use the Maven ant-run plugin and execute the hibernate-tools Ant task. So following the Thomas Letsch’s article I have worked out a solution that suits me well.
Table of Contents
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
I have bound the
run goal to the
test-compile phase so
<hibernatetool> will generate everything before running tests.
<configuration> tag’s body I have written my
target which starts,
and finish, with debug messages:
1 2 3 4 5
As described in “Using tasks not included in Ant’s default jar” 
I should have used
maven.plugin.classpath into the:
1 2 3
and than I should have written
hibernate-tools artifact, and all of
its dependencies, into the plugin’s
1 2 3 4 5 6 7 8 9 10 11
but because there are too many dependencies to write, as shown at
hibernate-tools depends on,
I have preferred to leverage on Maven dependency management declaring the
hibernate-tools artifact as one of my project dependency, leaving Maven
finding out the transitive dependencies:
1 2 3 4 5 6 7 8 9 10
Moreover because dependencies on
maven.plugin.classpath are not
packaged in the jar I have explicity excluded
hibernate-tools, and its dependencies,
from my project packaging declaring them in the
test scope. Thus
hibernate-tools dependencies were both on the
maven.test.classpath, so I have defined
 that groups the compile and the test classpath.
1 2 3 4 5 6
Despite what states the documentation about referencing the Maven classpaths
<pathelement path="maven.test.classpath" />
does not work for my project. So I have set ant
properties that refer to appropriate Maven classpaths.
In the end the
hibernatetool task definition looks like:
1 2 3
Finally I have configured the
hibernatetool to export a ddl file
1 2 3 4 5 6 7 8 9 10 11 12
Of course just before the
hibernatetool tag I have defined and created such
1 2 3 4 5
You can download the full pom from my GitHub account.
To generate DDL, or see
pom.xml with different
you may look at one of the following Maven project:
mvn clean test.
- Generate DDL with Hibernate Tools, JPA and Maven:
an excellent work by Thomas Letsch about
<hibernatetool>Ant Task and Maven
- Hibernate Tools Reference Guide: in particular the chapter about “Ant Tools”.
- The Maven AntRun Plugin: in particular the examples Referencing the Maven Classpaths and Using tasks not included in Ant’s default jar
- Path-like structures