Hibernate version:
hibernate-3.2
Hibernate Tools version:
HibernateTools-3.2.0.beta9a.zip
I'm trying to use the Hibernate Tools hbm2java task to create my POJOs. Basically I'd like to create hbm.xml files and define my domain objects via xml. Then I'd like to run hbm2java to generate my POJOs for me. Is this the right tool?
If so, I don't quite understand the configuration and setup that I'm supposed to be using. I have the hibernate tool configured to point to my hibernate.cfg.xml file in ./src. I also have a Person.hbm.xml file in ./src/org/enology/model/dao/Person.hbm.xml.
If I run the hbm2xml task and DO NOT have my Person.hbm.xml file mapped in it, it does not create a POJO for it.
If I do map it in hibermat.cfg.xml and I do not yet have a Person.java created, then it complains that it cannot find class Person while looking for the property id.
I then have to create a Person class with all the properties in it, otherwise I get an exception on any property that does not exist in it.
It seems I've gotten myself into a bit of a chicken and egg situation here. Clearly it makes not sense to use the tool to generate POJOs for you, if you have create them before hand.
Please find my build.xml below, and let me know if there's something I'm doing wrong:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<project name="vinotrails" default="dist" basedir=".">
<description>
simple example build file
</description>
<!-- set global properties for this build -->
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<property name="jdbc.driver.jar" location="../deps/hsqldb/lib/hsqldb.jar"/>
<path id="toolslib">
<path location="lib/hibernate-tools.jar" />
<path location="../deps/hibernate-3.2/hibernate3.jar" />
<path location="lib/freemarker.jar" />
<path location="${jdbc.driver.jar}" />
<path location="../deps/hibernate-3.2/lib/log4j-1.2.11.jar"/>
<path location="../deps/hibernate-3.2/lib/commons-logging-1.0.4.jar"/>
<path location="../deps/hibernate-3.2/lib/commons-collections-2.1.1.jar"/>
<path location="../deps/hibernate-3.2/lib/dom4j-1.6.1.jar"/>
<path location="${src}"/>
<path location="${build}"/>
</path>
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="toolslib" />
<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
</target>
<target name="compile" depends="init"
description="compile the source " >
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}"/>
<hibernatetool destdir="${src}">
<configuration configurationfile="${src}/hibernate.cfg.xml"/>
<hbm2java/>
</hibernatetool>
</target>
<target name="dist" depends="compile"
description="generate the distribution" >
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib"/>
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/lib/vinotrails-${DSTAMP}.jar" basedir="${build}"/>
</target>
<target name="clean"
description="clean up" >
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
</project>