Maven Hibernate3 Plug-in

This plugin provides easy integration with Hibernate 3.x for your project.

Before Starting

Before using, setup your project as described here: Using Sandbox Plugins

How to Use

In the pom.xml, insert this segment.

<project>
   ...
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>hibernate3-maven-plugin</artifactId>
                <version>1.0-SNAPSHOT</version>
                <configuration>
                    <hibernate>
                        <configurationFile>/src/main/resources/hibernate.cfg.xml</configurationFile>
                    </hibernate>
                    <outputDirectory>
                        <hbm2cfgxml>src/main/resources</hbm2cfgxml>
                    </outputDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>
   ...
</project>

Also you need to add your JDBC driver as an extension describe as follows.

<project>
...
  <build>
    <extensions>
      <extension>
        <groupId>jdbc.artifact.groupid</groupId>
        <artifactId>jdbc-driver</artifactId>
        <version>1.0</version>
      </extension>
    </extensions>
    ...
  </build>
</project>
  • Note: To be able to run the plugin you don't need to add the hibernate jars as dependency in your pom.xml

Running the plugin to generate DDL scripts based on JPA annotations

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>hibernate3-maven-plugin</artifactId>
                <version>1.0-SNAPSHOT</version>
                <configuration>
                    <hibernate>
                        <propertyFile>/src/main/conf/hbm2ddl.properties</propertyFile>
                    </hibernate>
                    <!-- if left out it will execute directly on your database instead -->
                    <outputFile>${project.artifactId}_create_tabless.sql</outputFile>
                </configuration>
                <dependencies>
                    <!-- Overriding plugin depenencies might be needed if the plugin is not up to date -->
                    <dependency>
                        <groupId>javax.persistence</groupId>
                        <artifactId>persistence-api</artifactId>
                        <version>1.0</version>
                    </dependency>
                    <dependency>
                        <groupId>org.hibernate</groupId>
                        <artifactId>hibernate</artifactId>
                        <version>3.2.0.cr4</version>
                    </dependency>
                    <dependency>
                        <groupId>org.hibernate</groupId>
                        <artifactId>hibernate-annotations</artifactId>
                        <version>3.2.0.cr2</version>
                        <exclusions>
                            <exclusion>
                                <groupId>javax.persistence</groupId>
                                <artifactId>ejb</artifactId>
                            </exclusion>
                        </exclusions>
                    </dependency>

                    <!-- JDBC driver is not required for hbm2ddl with outputFile -->
                    <!--
                        <dependency>
                            <groupId>net.sourceforge.jtds</groupId>
                            <artifactId>jtds</artifactId>
                            <version>1.2</version>
                        </dependency>
                    -->
                </dependencies>
            </plugin>

hbm2ddl.properties just needs something like this:

hibernate.dialect = org.hibernate.dialect.SQLServerDialect