-->
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: Generating custom code in DAO
PostPosted: Sat Mar 10, 2007 6:58 am 
Newbie

Joined: Wed Aug 25, 2004 2:23 am
Posts: 4
Location: Ukraine, Kyiv
Besides all existing methods in DAOs generated by Hibernate-Tools, I want to make it generate a method List <E> loadAll(). How can I do that?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 11, 2007 6:15 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Modify the existing generation script.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 12, 2007 11:11 am 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
1) Extract the daohome.ftl freemarker template from the hibernate-tools.jar (in the root dao package). Put it somewhere in your project (I would use templates/dao).

2) Modify the freemarker template as needed (see hint at the bottom of post)

3) Run the reverse engineering specifying the custom template location (in console, check "Use custom templates" and point to the templates folder).

4) Sit back and enjoy.


P.S. If you do not know/have time to learn Freemarker, just stick this in the template where you want the method to appear (untested):
Code:
    public ${pojo.importType("java.util.List")}<${declarationName}> loadAll() {
        log.debug("getting all ${declarationName} instances");
        try {
            ${pojo.importType("java.util.List")}<${declarationName}> data = sessionFactory.getCurrentSession().createCriteria("${clazz.entityName}");
            log.debug("getAll successful");
            return data;
        }
        catch (RuntimeException re) {
            log.error("getAll failed", re);
            throw re;
        }
    }


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 12, 2007 8:29 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Cool - thanks for the extended answer.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 15, 2007 6:23 pm 
Newbie

Joined: Wed Aug 25, 2004 2:23 am
Posts: 4
Location: Ukraine, Kyiv
Ananasi, thanks a lot.


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.