-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Automatically generate "finder" attribute in hbm f
PostPosted: Mon Dec 22, 2008 7:39 pm 
Newbie

Joined: Mon Dec 22, 2008 7:26 pm
Posts: 6
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.