-->
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.  [ 3 posts ] 
Author Message
 Post subject: Generic DAO generation
PostPosted: Tue Sep 20, 2005 3:42 pm 
Beginner
Beginner

Joined: Thu Aug 04, 2005 8:41 pm
Posts: 47
Hello,

I wanted to try recent java 5.0 DAO generation with Hibernate tools. I've
downloaded latest night build. Can you, please, point me
what should I put into my ant build.xml for DAO generation
(those DAOs which use generics)?

Thanks,

Code:
<?xml version="1.0"?>
<project name="HibernateTool Generator" default="hbm2x">
  <property name="my.root.dir" value="${basedir}"/>
  <property name="src.dir" value="${basedir}/src"/>
  <property name="hbm.cfg.dir" value="${basedir}/src"/>
  <path id="classpath">
    <pathelement location="${basedir}"/>
    <fileset dir="${basedir}/lib">
      <include name="**/*.jar"/>
    </fileset>
  </path>
  <!-- =================================================================== -->
  <!-- Generates java source code from hibernate mappings (*.hbm.xml)      -->
  <!-- =================================================================== -->
  <target name="hbm2x" description="Generate java source code from hibernate mappings">
    <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="classpath"/>
    <hibernatetool destdir="${basedir}/src">
      <configuration configurationfile="${hbm.cfg.dir}/hibernate-iocm.cfg.xml">
        <fileset dir="${basedir}/src">
          <!-- A configuration can take a configurationfile and/or a fileset of hbm.xml's -->
          <include name="**/*.hbm.xml"/>
        </fileset>
      </configuration>

      <!-- code generation -->
      <hbm2java generics="true"/>

      <!-- code generation with custom templates (yes, can run each task more than once! -->
      <hbm2java templatespath="${basedir}/velocity/dao"/>

      <!-- Generate documentation -->
      <hbm2doc/>

      <!-- Generate DAOs -->
      <!--
      <hbm2dao/>
      -->

      <!-- Generate JSF -->
      <!--
      <hbm2jsf/>
      -->

      <!-- Schema export -->
      <hbm2ddl drop="false" format="true" outputfilename="db-init.sql"/>

    </hibernatetool>
  </target>
</project>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 9:33 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
There isn't an ant task for hbm2dao yet, and the closest you'd get would not resemble the CE stuff . You're going to want to remove that hbm2jsf element for a while also, it's uncommitted and untested.

Patience ;-)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 23, 2005 1:28 pm 
Beginner
Beginner

Joined: Sat Sep 17, 2005 10:41 am
Posts: 49
Correct me if I am wrong, but isn't code generation for DAO classes on Java 1.5 redundant? You can already make a generic DAO:

Code:
public class Customer extends Persistent {
// persistent POJO class
}

public class Dao<T extends Persistent> {
  public List<T> list () { ... }
  // etc
}

public class DaoFactory {
  public Dao<T> getDao (<T extends Persistent> pojoClass) {
    return new Dao<pojoClass>() ;
  }
}


This way, you write class Dao and DaoFactory once, and you're done. No need for code generation...


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

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.