Hello,
I am using hibernate tools 3.2.4 along with ant 1.6.5. I am generating mapping files using hbm2hbmxml, configuration files using hbm2cfgxml and pojos using hbm2java. I am also generating DAOs using hbmtemplate. I am including finders in the DAOs for each column in the database tables and, in order to make this completely automated, I would like the reverse engineering to automatically generate the required "finder" attribute entries in the hbm file but do not know how to do this. Can any one offer any suggestions?
This is my build file:
Code:
<project name="MyProject" default="codegen" basedir=".">
<description>
simple example build file
</description>
<path id="toolslib">
<fileset dir="./lib" includes="*.jar"/>
</path>
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="toolslib"/>
<!-- set global properties for this build -->
<property name="hibernate" location="hibernate"/>
<property name="target" location="target"/>
<target name="codegen" depends="cfggen, mapgen"
description="Generate Java source code
from the Hibernate mapping files">
<hibernatetool destdir="${target}" templatepath="${hibernate}">
<classpath>
<path location="${hibernate}"/>
</classpath>
<configuration configurationfile="${hibernate}/hibernate.cfg.xml"/>
<hbmtemplate
templatepath="${hibernate}"
template="daotemplate.ftl"
filepattern="{package-name}/{class-name}DAO.java">
<property key="jdk5" value="true" />
<property key="ejb3" value="false" />
</hbmtemplate>
<hbm2java/>
<hbm2dao/>
</hibernatetool>
</target>
<target name="mapgen" depends="cfggen"
description="Generate Java source code
from the Hibernate mapping files">
<hibernatetool destdir="${hibernate}">
<classpath>
<path location="."/>
</classpath>
<jdbcconfiguration configurationfile="${hibernate}/hibernate.cfg.xml" revengfile="hibernate.reveng.xml"/>
<hbm2hbmxml/>
</hibernatetool>
</target>
<target name="cfggen"
description="Generate Java source code
from the Hibernate mapping files">
<hibernatetool destdir="${hibernate}">
<classpath>
<path location="."/>
</classpath>
<jdbcconfiguration configurationfile="hibernate.cfg.xml" revengfile="hibernate.reveng.xml"/>
<hbm2cfgxml/>
</hibernatetool>
</target>
</project>
This is a sample hbm file:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Dec 22, 2008 2:24:04 PM by Hibernate Tools 3.2.2.GA -->
<hibernate-mapping>
<class name="com.structuralwealth.clientdatabase.hibernate.HibernateUserMap" table="UserMap" catalog="ClientTrunk">
<id name="id" type="java.lang.Long">
<column name="id" />
<generator class="identity" />
</id>
<property name="naturalPersonId" type="java.lang.Long">
<meta attribute="finder">findByNaturalPersonId</meta>
<column name="natural_person_id" />
</property>
</class>
</hibernate-mapping>
Thanks.