-->
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: hbm2java: how can I put own object into velocity context?
PostPosted: Mon Sep 05, 2005 4:55 am 
Newbie

Joined: Fri Dec 12, 2003 9:08 am
Posts: 9
Hello,

I'm using hibernate tools 3.1.0alpha5 inside eclipse 3.1 and it works great!

Now, I would like to do some changes to pojoclass.vm and would like to put an object into the velocity context, which would help me during code generation.

As far as I can tell from the code, there is no simple way to achieve this. POJOExporter has a protected method setupContext, which I could override and use, but I wouldn't be able to make the Hbm2JavaGeneratorTask or the ArtifactGeneratorWizard of the eclipse plugin use my own POJOExporter:

- HibernateToolTask instantiates a Hbm2JavaGeneratorTask, which in turn instantiates a POJOExporter

- ArtifactGenerationWizard directly instantiates a POJOExporter

Am I missing something?

Many thanks for this great tool!

Kambiz


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 8:23 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
its something we want to add as a possibilty....

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 8:35 am 
Newbie

Joined: Fri Dec 12, 2003 9:08 am
Posts: 9
In the meantime, I've patched Hbm2JavaGeneratorTask to add a new configuration option exporter.

If it is set, the custom exporter is instantiated using the defaut constructor.

I will try to figure out how I could modify hibernate console, add tests etc. and submit a patch to the JIRA.

Thanks

Kambiz


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 8:49 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
one thing we would like is something like:

<generate class="<some class that is a Exporter>" template="templatename that will be used" filename="velocitysnippet-to-generate-the-filename"/>

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 9:31 am 
Newbie

Joined: Fri Dec 12, 2003 9:08 am
Posts: 9
Quote:
<generate class="<some class that is a Exporter>" template="templatename that will be used" filename="velocitysnippet-to-generate-the-filename"/>


Where do you want this to be configured?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 9:35 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
first off via ant

later on we'll have to extend the Exporter interface/class to be more configurable and then we can clean up the ui for the artifact generator and let it be more dynamic.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 9:58 am 
Newbie

Joined: Fri Dec 12, 2003 9:08 am
Posts: 9
Sorry, that I have to ask again.

This is how my current solution looks like:

Quote:
<hbm2java ejb3="true" templatespath="${templatespath}"
exporter="my.own.CustomPojoExporter"/>


Do you mean:

Quote:
<hbm2java ejb3="true" templatespath="${templatespath}" >
<generate class="my.own.CustomPojoExporter" template="templatename that will be used" filename="velocitysnippet-to-generate-the-filename"/>
</hbm2java>


As I understand, you would like to have the ability to generate multiple artifacts, which could have different exporters, different templates (instead of hard-coded "pojo/javaclass.vm" and different names for the generated files.

Or if not, could you please sketch how the ant config should look like.

And could you please give an example of velocitysnippet-to-generate-the-filename?

Thanks

Kambiz


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 10:05 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes your example is correct.

the filename is not vital for the first attempt - could just assume the exporter handles it.

but the idea was simply to allow filename="${classname}Something.java" which would generate a file per class or "Something.xxx" which would only generate one file namely "Soemthing.xxx"

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 5:27 am 
Newbie

Joined: Fri Dec 12, 2003 9:08 am
Posts: 9
I've patched the code to allow for a custom PojoExporter and specifying your own template name.

Syntax of ant task would be like this:

Code:
<hbm2java generics="true" ejb3="false"
    exporter="my.own.CustomPojoExporter"
    template="pojo/my_own_dao_template.vm"
    namepattern="#class#DAO.java"  />


I've also added some tests to anttest-build.xml and HibernateToolTest.

I there already a JIRA issue where I can attach the patch or do I have to open a new one?

Thanks

Kambiz


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 6:44 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
should be on a new one ....

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