-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hibernate as DAO code generator
PostPosted: Fri Feb 20, 2004 11:41 am 
Beginner
Beginner

Joined: Thu Dec 11, 2003 12:02 pm
Posts: 23
Has anyone used hibernate simply as a RAD dao code generator? (pun intended).

I work at a company where the persistence layer is hand written for various reasons. I am wondering if there is a way to make hibernate output a file something like the following pseduo code below (Assume customer.hbm.xml already exists).

Code:
public class customerDAO{

   public insertCustomer(Customer customer){
       connx = getConnx();
       connx.set...
       insert into CSTMR (customerId, customerName) values (...)
   }


   public updateCustomer(Customer customer){
      connx = getConnx();
      connx.set...
      update CSTMR ....
   }


   public deleteCustomer(Customer customer){

   }


It would save me time from looking up the database field names, getting the corresponding property of the value object, etc.

I guess because the .hbm.xml file is available I could create a custom xml parser, parse the file, and spit out the code above based on any preferences I have.

Any thoughts or ideas for other ways to do this?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2004 11:45 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
The hbm2java tool (Hibernate Extensions) already has some templates for basic finder/DAO generation. More velocity templates would certainly be very welcome, check it out.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2004 1:39 pm 
Beginner
Beginner

Joined: Thu Dec 11, 2003 12:02 pm
Posts: 23
I couldn't find any reference to a velocity template (*.vm) being used in hibernate extensions (hbm2java) or hibernate2.1.2

It appears to me that hbm2.java builds the java files directly and does not consult an external template.

Can you please tell me what the external template file hbm2java uses to build the java code and where it is located. Also if you have the DAO templates or know where to download them that would be nice too.

Thankx.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2004 1:46 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You can enable the Velocity based renderer by specifying

Code:
<codegen>
<generate renderer="net.sf.hibernate.tool.hbm2java.VelocityRenderer">
<param name="template">pojo.vm</param>
</generate>
</codegen>

in the config.xml


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 20, 2004 9:26 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
....but PLEEASE be aware that velocity su...eh, is hard to use with respect to proper code generation....but hey - it's a free world ;)

I would recommend extending the current BasicRenderer or utilize the helper code to write a custom Renderer.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.