So im trying to use Hibernate Tools to reverse engineer my database and I am just getting into using Freemarker templates to weak the code it generates. The problem is I want to change the name of the DAO classes it generates. By default the DAO classes are named in the form PersonHome however to change the name to PersonDAO i modified the dao/daohome.ftl.
While this did change the generated class name to PersonDAO the java file was still called PersonHome.java.
Is there a place I can also change the generated file name to match the source code?
Ok well I have got to the bottom of it myself. It seems while hibernate tools does support changing the filename the feature is not exposed in the Hibernate tools plugin for Eclipse which is frustrating. Instead I have had to create an ant build script to run the reverse engineering like follows.
<project name="Reverse Engineer" basedir=".">
<path id="toolslib">
<path location="lib/hibernate3.jar" />
<path location="lib/hibernate-tools.jar" />
<path location="lib/freemarker.jar" />
...
<path location="${jdbc.driver.jar}" />
</path>
<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask"
classpathref="toolslib" />
<hibernatetool destdir="src">
<jdbcconfiguration
configurationfile="src/hibernate.cfg.xml"
packagename="my.package.name"
revengfile="hibernate.reveng.xml">
</jdbcconfiguration>
<hbmtemplate destdir="src"
templatepath="templates"
template="dao/daohome.ftl"
filepattern="{package-name}/{class-name}DAO.java">
<property key="ejb3" value="false" />
<property key="jdk5" value="true" />
<property key="sessionFactoryName" value="my.HibernateSessionFactory" />
</hbmtemplate>
</hibernatetool>
Use "Generic Exporter <hibernatetemplate>
" tool instead of "DAO Code(.java)
".
Along with it set the following attributes in the
templatename[customtemplate.ftl]
for this we may use the existing daohome.ftl
which is available in hibernate-tools.jar
.${package-name}\${class-name}DAO.java
and required properties like sessionFactoryName
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With