Child pages
  • Maven2 hibernate DDL generator POM
Skip to end of metadata
Go to start of metadata


This is a package of files which will make it easy to add database DDL generation to any maven 2 project which is using hibernate. It was so hard to get this working that I decided it really should be documented. This will allow you to generate DDL for mysql, oracle, derby, DB2, mssql, postgres, and hsqldb by just running a simple mvn command (after some setup).

Where do I get it?

You can download the files as a zip:
You can also see the files in SVN here:
Here is an example of a project which is using it:

How do I use it?

Just follow the readme.txt file which is included with the files. It is reproduced below so you can get a sense of the work involved:

You must have the following:
1) Java and Maven 2 installed and your project setup as a maven 2 project
2) A set of hibernate HBM files and matching persistent POJOs
3) A project structure like so (where impl is the root directory in this case):

  • src
    • java
      • **.hbm.xml

How to use this:
1) Copy the contents of this zip/folder into a impl/src/ddl folder (referred to as the ddl folder) so that all the files included are located inside your source code tree
NOTE: You cannot copy this into a folder which already contains a pom.xml
2) Edit the pom.xml file
2A) Change the name, groupId, and artifactId to match your project:
<name>Sakai Hierarchy DB DDL generator</name>
2B) Change the parent POM to refer to your project base POM, if you have no project base POM then you can remove the <parent> tag
<!-- this should refer to your project base POM -->
2C) Change the to match your project, this will be the name used for the ddl files (example: hierarchy.sql)
<!-- change this to reflect the name to use for the ddl files -->
2D) Change the dependencies to pull in your hibernate persistent POJOs (these are needed in order to process the HBM files)
<!-- this should pull in your hibernate persistent POJOs -->
2E) Change the build resources to pull in your .hbm.xml files
<!-- this should pull in your .hbm.xml files -->
3) Edit the hibernate.cfg.xml file,
the mapping resources must point to all your HBM files
<!-- these mapping resource paths must point to your hibernate template files (.hbm.xml),
this should be the classpath location (typically after the src directory) -->
<mapping resource="org/sakaiproject/hierarchy/dao/hbm/HierarchyNodeMetaData.hbm.xml" />
<mapping resource="org/sakaiproject/hierarchy/dao/hbm/HierarchyPersistentNode.hbm.xml" />
4) Run maven 2 to generate the DDL from the ddl folder: mvn install
You should now have a new set of folders inside the ddl folder, each one will contain a ddl file for a specific database with the database name as the name of the folder containing the ddl file
Example: ddl/mysql/hierarchy.sql

That's all there is to it.

1 Comment

  1. If in maven 3 change the plugin version to 2.2