-->
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.  [ 10 posts ] 
Author Message
 Post subject: Hibernate tool & custom templates
PostPosted: Wed May 24, 2006 10:18 pm 
Newbie

Joined: Wed May 24, 2006 9:45 pm
Posts: 10
Hi all,

I'm trying to use hibernate tool + eclipse. It works fine but I got a problem.

I want to customize the dao generation... I have copied and change the daohome.tfl in hibernate tools and put it in xpto dir.

When I run the code generation I choose the option "use custom templates" and put "xpto" in the "template directory" field(xpto is the directory where I put my modifed daohome.tfl)

But when I click "run", I get the generated dao but my template was ignored. The tool still uses the daohome.tfl that is in the jar....

What kind of file should be in the "template directory" field? tfl files? velocity files? I read something about velocity in the forum....

Question: I want to customize a template(i think that should be a tfl file) and run it inside the tool, without ant tasks. Is this possible? How should I proceed?

Thank you all,

Excuses for any english mistakes...


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 25, 2006 5:17 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
we apparently have a bug of how it detect the .ftl files.

it should just pick them up without you having to maintain the dir structure but that seem not to work.

Thus put the files int somepath/dao/daohome.ftl and then somepath is what should be used for template path.

your last question i don't completely understand...?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 25, 2006 7:46 am 
Newbie

Joined: Wed May 24, 2006 9:45 pm
Posts: 10
Thank you max, I'll try your suggestion.

My last question, in fact, wasn't a question. I have tried to give you a shortcut for the long text that came before....

Can you tell me more about the dir names and file names? The DAO template must be named daohome.tfl?

What the names of the other directories for other exports? Must be the same as the tool.jar?

At last, I was thinking to use interfaces in my DAO. Can I generate two files at the same time(interface + dao)?

How does the tool work? Does it executes all .tfl file in a directory? If yes, I think that I should just create a xxxInterface.tfl and put it together with daohome.tlf. Am I right?

Thank you again.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 25, 2006 8:18 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Bjornn Borg wrote:
Can you tell me more about the dir names and file names? The DAO template must be named daohome.tfl?


dao/daohome.ftl, just like it is named in hibernate-tools.jar

Quote:
What the names of the other directories for other exports? Must be the same as the tool.jar?


just like in hibernate-tools.jar

Quote:
At last, I was thinking to use interfaces in my DAO. Can I generate two files at the same time(interface + dao)?


just add two runs of <hbmtemplate>

Quote:
How does the tool work? Does it executes all .tfl file in a directory? If yes, I think that I should just create a xxxInterface.tfl and put it together with daohome.tlf. Am I right?


no ;)

the tool is controlled by an Exporter class (which you also can override) which normally just looksup a specific .ftl file and then "executes" it with appropriate input.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 26, 2006 10:17 am 
Newbie

Joined: Wed May 24, 2006 9:45 pm
Posts: 10
Hi, I'm trying to write my own templates according some templates that exists in hibernatetool.jar.

My Idea is auto-generate interfaces for each DAO. At first I have copied daohome.ftl from hibernatetool.jar and made some changes. It have worked fine after your reply above...

But I think that I don't need this complex template and have decide to write to my own(And I want to learn too...). I got a thousand doubts and mistakes and problems... heheheh.

I have read the freemarker documentation and I think that I understand what it is and what it does.... but I cannot understand code line that exists in your template like this: ${pojo.getPackageDeclaration()}

I have lookup in hibernatetool.jar and I found Pojo.class and several others... but I cannot understand how they fit together... what does the pojo class? I saw some interfaces, classes, but I don't remeber nothing like this in freemarker documentation.

in short: I want to use hibernatetool with ant, and according the existing classes in a specified dir(pojo dir) generate the interface and the DAO class. I think I should be able to receive some parameter in my template(like "class_name") and write "public class ${class_name}..." But how make ant pass this parameters? In my mind, I should use a fileset task and invoke the template for each file.... how I do this?

If you have a link to a tutorial or something like this...

That's enougth... I hope you should be able to understant what I said...

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 26, 2006 1:02 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
${pojo.getPackageDeclaration()} refers to PojoClass.getPackageDeclaration() which returns the package declaration....surprise :)

if you want to put you own values/classes into the templates then see
http://www.hibernate.org/hib_docs/tools ... e/#d0e1115

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 26, 2006 3:49 pm 
Newbie

Joined: Wed May 24, 2006 9:45 pm
Posts: 10
I read the tutorial... Give me a word about what I want to do...

I think that I could create a class with a "main" method(e.g. ClassX) that receives the class name, etc... and this class locates the template, and creates a parameter map to fill it....like the freemarker tutorial...

So, in my build file I could invoke the ClassX with the java task passing a class name(to be generated) as a parameter... and ClassX will create a map with key/value(e.g. "interface_name", "MyInterface") and pass it to the ftl file... Would it work?

I'm looking the classes in hibernatetool.jar and I think that exporters are like this.... But more advanced and professional... Am I right?

Or maybe, I just should extend AbstractExporter.... I'm studing this class right now...

Thanks again..


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 26, 2006 5:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
are you asking about how I implemented it or how you are should write your own templates ?

the templates can just be written by using some of the existing ones as a starting point and then just use <hbmtemplate> to apply them.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Re: Hibernate tool & custom templates
PostPosted: Tue Oct 27, 2009 6:56 am 
Beginner
Beginner

Joined: Wed May 23, 2007 1:07 pm
Posts: 28
My question is related to the firs user's: how can one use a custom DAOExporter in Eclipse's hibernate tools?

I can't seem to find a way to tell the exporter that I want to use my own overridden class to do the export in Hibernate configurations!


Top
 Profile  
 
 Post subject: Re: Hibernate tool & custom templates
PostPosted: Tue Nov 17, 2009 10:08 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you can use the hbmtemplate in eclipse which allow you to configure the same properties in eclipse as in ant.

_________________
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.  [ 10 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.