-->
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: Adding custom exporter by extending toolset vs. modifying?
PostPosted: Tue Nov 15, 2005 7:21 pm 
Beginner
Beginner

Joined: Tue Nov 15, 2005 6:56 pm
Posts: 39
Using HibernateTools3.1.0Beta1.

Trying to figure out best way to add an exporter without modifying code but rather extending the toolset. Is there a way?

My particular need for the custom exporter is explained below.

I'm trying to figure out which is the best way to programmatically set the meta attribute "use-in-equals" on properties. Basically, I know I want to do some code like this:

Code:
property.getMetaAttributes().put("use-in-equals", meta);


1) Is the above code the best way to do this?
2) Which is the best place to put the code? Preferably extending the classes rather than rewriting them would be better.

I originally thought of creating my own MyHbm2JavaGeneratorTask class and MyHibernateToolTask classes. The plan was to have MyHbernateToolTask derive from HibernateToolTask and just add this method:

Code:
   
public ExporterTask createMyHbm2Java() {
   ExporterTask generator = new MyHbm2JavaGeneratorTask(this);
      generators.add(generator);
      return generator;
   }


MyHbm2JavaGeneratorTask.confiureExporter would programmatically add the "use-in-equals" meta attribute.

Unfortunately, the generators member field is private in the super class HibernateToolTask, so I couldn't do it this way. The other solution that does work is to just create a new class parallel, instead of derived, to the HibernateToolTask and duplicate all the code and add my extra method. This, however, was what I didn't want to do since it involved changing the existing code.

So, essentially, I think my problem can be more generally stated as how does one add a custom exporter task by extending the toolset rather than modifying it? Is there a way?

Any help is appreciated.

Thank You.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 16, 2005 5:09 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hmm - so you want to alter the hibernate meta model *before* it is handed to the exporters.

That is doable if you simply just add a <hbmtemplate class="your.mutator.ClassName"/> which will be handed a Configuration which you can actually modify (be carefull and remeber to call cfg.buildMappings() ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: How to use <hbmtemplate> exporter?
PostPosted: Wed Nov 16, 2005 5:11 pm 
Beginner
Beginner

Joined: Tue Nov 15, 2005 6:56 pm
Posts: 39
Thank you for the suggestion. I'm a newbie to Hibernate, so I hope I understood you correctly.

I ended up deriving a class from GenericExporter and overriding the setConfiguration(...) method. I called the super classes setConfiguration method first and then did my code to add meta attributes to the configuration. Something like this in MyPOJOExporter.java:

Code:
public void setConfiguration(Configuration cfg) {
         super.setConfiguration(cfg);
         // my code here
}


I then called it in my ant file like this:

Code:
<hbmtemplate template="pojo.vm" exporterclass="com.mycompany.MyPOJOExporter" filepattern="{package-name}/{class-name}"/>


It seems to work. However, I did not end up calling cfg.buildMappings() like you warned about. Is that necessary and where do I call it?

Thanks for all your help.


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.