-->
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: hbm2dao: Class generation in different package
PostPosted: Fri Dec 08, 2006 5:07 am 
Newbie

Joined: Tue Dec 05, 2006 8:36 am
Posts: 7
Hibernate Tools version: 3.2-beta8

Hello,

Looking at the daohome.ftl, the same package is used for generation of the DAO (with hbm2dao) files by using ${pojo.getPackageDeclaration()}, i.e. the same package used by hbm2java to generate classes as specified in the hibernate mapping document.

Is there any way to specify a different package for DAO class generation? More exactly: When specifying a class to be part of package eg.hibernate, I simply want the DAO files to be put in eg.hibernate.dao

Cheers,
Matthias


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 08, 2006 9:49 am 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
Create your own daohome.ftl, based on the one in the hibernate-tools package and change the package declaration appropriately. This probably should be configurable. Anywho, an example

Code:
package eg.hibernate.dao;
// Generated ${date} by Hibernate Tools ${version}

<#assign classbody>
<#assign declarationName = pojo.importType(pojo.getDeclarationName())>/**
* Home object for domain model class ${declarationName}.
* @see ${pojo.getQualifiedDeclarationName()}
* @author Hibernate Tools
*/
// ...etc

Then you have to specify the templatepath and destdir (this is for Ant, I don't use the console much). As a benefit, you can tweak the dao generated to suit your needs much better this way as well. The dao generated by default is a bit skeletal for my needs, but futzing around with the templates allows me to generate dao interfaces and implementations, integrated bidirectional collection management, more finder methods, etc.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 08, 2006 10:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
currently the way to do it is to change the templates.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 01, 2007 12:07 am 
Newbie

Joined: Thu May 31, 2007 11:50 pm
Posts: 6
max wrote:
currently the way to do it is to change the templates.


I was trying to solve this same problem and came across this thread which describes almost the same way to solve it that I had taken. However the problem I'm having with it is trying to find a way to override the package. It seems like pojo.importType() does not add the package of the domain model to the import list since that is what your current package is set to, since it doesn't know I'm declaring a different package inside the template...

Is hardcoding this import the only way to handle this, or is there some way to override the package either by passing it in or setting/overriding it at the beginning of the template itself?

TIA!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 01, 2007 1:55 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
The pojo is defined to be in its own package context.

One (tricky) way to change that is to use a custom import context, e.g.

Code:
ic = new ImportContext("org.my.custom.pack");


and now you can use $ic in the same way and get it in the above context.

Maybe we should introduce a "main" importcontext variable that by default points to pojo but could be changed by the user to avoid having you change all the occurrences of $pojo.importType.

Feel free to submit a bug/patch for it.

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