views:

72

answers:

2

Hi,

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?

A: 

I didn't look closely at this but I think you'll have to modify the DAONewExporter class (see HBX-343 for some inspiration).

Pascal Thivent
+1  A: 

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>

murdoch