Hibernate Tools

References

Setup

Overview

  • The tools provide a number of features. This focuses on:
    • Defining and configurating the database through Annotations as much as practical
    • The console which allows viewing the configuration and the database tables
    • Generating DDL using an Ant task (to be moved under Maven)
  • Getting feedback on Annotated persistence classes is covered under Hibernate Annotation Dev

Depends On (updated Feb. 2015 for Luna)

  • JDK 7
  • Eclipse 4.4 (Luna) +

Steps

  1. Follow Hibernate Tools Install for Eclipse. This uses the Eclipse Update Software feature.
  2. Create Hibernate Console Configuration to allow checking/editing the config.
  3. Setup a build.xml for generating DDL:
<?xml version="1.0" encoding="UTF-8"?>
<project name="GenDDL" default="default" basedir=".">
 
    <path id="toolslib">
        <path location="N:\hibernate-3.2\lib\dom4j-1.6.1.jar" />
      <path location="N:\.m2\repository\commons-logging\commons-logging\1.1.1\commons-logging-1.1.1.jar" />
      <path location="M:\\download\\hibernate-tools-3.2.0.beta8.jar" />
      <path location="N:\.m2\repository\org/hibernate\hibernate\3.2.6.ga/hibernate-3.2.6.ga.jar" />
      <path location="N:\hibernate-annotations-3.3.1.GA\lib\hibernate-commons-annotations.jar" />
      <path location="N:\.m2\repository\hibernate-annotations\hibernate-annotations\3.3.1.GA_CP01-brew\hibernate-annotations-3.3.1.GA_CP01-brew.jar" />
        <path location="N:\.m2\repository\javax\persistence\persistence-api\1.0\persistence-api-1.0.jar" />
        <path location="N:\hibernate-3.2\lib\commons-collections-2.1.1.jar" />
        <path location="N:\.m2\repository\mysql\mysql-connector-java\3.1.14\mysql-connector-java-3.1.14.jar" />
     <!-- <path location="lib/freemarker.jar" /> 
     <path location="${jdbc.driver.jar}" /> -->
    </path>
 
    <taskdef name="hibernatetool" 
             classname="org.hibernate.tool.ant.HibernateToolTask" 
             classpathref="toolslib" />
 
    <target name="default"> 
      <hibernatetool destdir="target/sql/">
          <classpath>
              <path location="." />
            <path location="target/listTags-1.0-SNAPSHOT/WEB-INF/classes" />
          </classpath>
          <annotationconfiguration
            configurationfile="hibernate.cfg.xml"/>
            <hbm2ddl outputfilename="listTags.ddl" format="true"/>
        </hibernatetool>
    </target>
 
</project>
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License