-->
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: How to generate abstract and concrete classes for each table
PostPosted: Mon Feb 02, 2009 10:39 am 
Newbie

Joined: Mon Feb 02, 2009 10:15 am
Posts: 1
Hi all,
We're using HibernateTools 3.2.4.Beta1.

Because of some historic stuff, we need to reverseengineer *.hbm.xml and pojo's from a MS SQL DB.
We generate everthing with the ant task, provided by the hibernate tools

The default behaviour of hbm2java task is to generate one class per table.

What we need is a abstract class with all getter/setter of the table and a concrete subclass of the abstract class. (Like the EclipseTools with velocity) e.g.:

Code:
public abstract AbstractUser extends BaseObject{
   public String getUser() {...}
   public void setUser(String user) {...}
}

public User extends AbstractUser {
// my Custom Code
}


The BaseObject is no problem (added following to the hibernate.reveng.xml)
Code:
   <table-filter match-name=".*">
         <!-- add any global meta attributes for tables here -->
         <meta attribute="extends">BaseObject</meta>
     </table-filter>


But how can we achieve the automatic generation of Abstract-Class and the concret class for each table/view ?
We have more then 300 tables, so we can't configure each table manually

Thanx
Jürgen


Top
 Profile  
 
 Post subject: RE: How to generate abstract and concrete classes for each t
PostPosted: Fri Feb 06, 2009 6:16 pm 
Newbie

Joined: Tue Mar 23, 2004 4:38 pm
Posts: 3
Hi Jürgen-

I've done what you're describing by using 2 custom templates, one that generates the abstract class and the other that generates the concrete class:

<!-- based on generated hbm.xml files, generate
abstract pojo instances using custom templates -->

<hbmtemplate
destdir="${root.dir}/generated"
filepattern="com/x/dao/Abstract{class-name}.java"
templatepath="${root.dir}/build/hibernate/template/abstract"
templateprefix="pojo/"
template="pojo/Pojo.ftl">
<property key="jdk5" value="true"/>
<property key="ejb3" value="false"/>
<property key="parentClass" value="com.wrigley.web.dao.DaoObject"/>
</hbmtemplate>

<!-- based on generated hbm.xml files, generate
concrete pojo instances using custom templates -->

<hbmtemplate
destdir="${root.dir}/generated"
filepattern="com/x/dao/{class-name}.java"
templatepath="${root.dir}/build/hibernate/template/concrete"
templateprefix="pojo/"
template="pojo/Pojo.ftl">
<property key="jdk5" value="true"/>
<property key="ejb3" value="false"/>
</hbmtemplate>
</hibernatetool>


As you can see, I use a 'workspace' directory called generated as the target for all the assets generated during reverse engineering. When the task wraps up I have 2 ant copy calls, one which over writes and selects only those assets I want overwritten (like the hbm.xml files and the abstract classes) and another copy that does not write for the concrete classes. The final step is of course to delete the generated directory.

HTH,

Jim


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2009 6:50 pm 
Newbie

Joined: Mon Feb 02, 2009 2:49 pm
Posts: 15
It's funny. Max and I have been talking about largely the same thing in another thread (generating annotated pojos).

I am wanting to do this, but with annotated pojos, so the custom templates are a bit more difficult. Also, I wanted to use built-in templates, so that I don't have to keep mine up, I can just get updates from the project.


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.