-->
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.  [ 7 posts ] 
Author Message
 Post subject: Is there a HowTo available for custom exporters?
PostPosted: Mon Feb 13, 2006 12:19 pm 
Beginner
Beginner

Joined: Thu Nov 25, 2004 7:07 am
Posts: 43
Location: Germany
Is there a complete HowTo available on how to write my custom exporter class? The documentation for Ant tools is not sufficient for me. I want to understand what I do.

There are several problems.

How do I generate Interfaces for my POJO classes?

I tried to configure as max proposed in an other thread:
Code:
<hbmtemplate             
  filepattern="{package-name}/I{class-name}Proxy.vm"
  template="Pojo.vm"
  exporterclass="org.hibernate.tool.hbm2x.POJOExporter" />


But there are no Interfaces generated.

I want to generate base classes for my POJOs like HibernateSynchronizer does. But modifying the template didn't bring a solution.

Is anybody out there who has a complete "step-by-step" document what to do to achieve something like this?

Rgds,
Axel

_________________
You'll never get a second chance to make a first impression!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 13, 2006 12:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
What do you want a howto for ?

How to write an custom exporter or how to do that specific thing ?

the specific thing is not exactly trivial, but on the roadmap.

If you want to do it (probably easy if you have a limited usage scenario) then i don't remember i have told someone to specify both a template and pojoexporter....if i did, then it is outdated ;)

There are an example here on how to do it: http://www.hibernate.org/hib_docs/tools ... bmtemplate

let me know what error message/output you actually get etc. and what is the content of your own Pojo.vm ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 13, 2006 12:48 pm 
Beginner
Beginner

Joined: Thu Nov 25, 2004 7:07 am
Posts: 43
Location: Germany
That is the documentation I already read, but I don't have a clue how the components work together. So I thought it would be easier with a step-by-step document on how to write a custom exporter. I don't get a real error message - but the java classes don't look like expected.

E.g.

The base classes are generated, but they are not extended from my own class I specified. The base classes have a prefix "Base" - this is ok, as I configured it like that.

But the normal POJO which should extend the BaseClass are generated in the same package. I'd like to have them one directory above.

The interfaces are never generated - it seems that pojo.isInterface() always returns false.

I already had a look on the source code for GenericExporter and POJOExporter, but the code is not very well documented and so I don't find a point of entry where I could start writing my custom exporter. Or do I have to start earlier and write my own ReverseEngineeringStrategy? If I understood right, I don't need this.

_________________
You'll never get a second chance to make a first impression!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 13, 2006 1:05 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
no you dont need to write a custom reverse engineering. reverse engineering is only for reading from thedatabase to the hibernate meta model.

but do you really just want all classes to implement a specific interface and that interface should have the setter/getters specificed for properties in the mapping files ?

That sounds like an evil dual class hiearchy just for fun scheme...and i don't think that is what synchronizer does is it ? It generates a baseclass(not interface) and that case is in a on-the-road-map jira task

Anyway, if you just have a simple scenario where all your packages are in a single package you can do something like the following:

<!-- generate base interface -->
<hbmtemplate
filepattern="your.single.rooted.pkgname/I{class-name}Proxy.java"
template="yourinterfacetemplate.vm"
/>

where yourinterfacetemplate.vm does what Pojo.vm does today if something is an interface + modify it to generate the correct classname.
(you might need to have more than just a modified pojo.vm)

<!-- generate base interface -->
<hbmtemplate
filepattern="{package-name}/{class-name}.java"
template="yourmodifiedPOJOTypeDeclaration.vm"
/>

here yourmodifiedPOJOTypeDeclaration.vm is PojoTypeDeclaration but with your custom "implements".

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 15, 2006 8:47 am 
Beginner
Beginner

Joined: Thu Nov 25, 2004 7:07 am
Posts: 43
Location: Germany
Sorry for bothering again.

max wrote:
but do you really just want all classes to implement a specific interface and that interface should have the setter/getters specificed for properties in the mapping files ?

That sounds like an evil dual class hiearchy just for fun scheme...and i don't think that is what synchronizer does is it ? It generates a baseclass(not interface) and that case is in a on-the-road-map jira task

Ok, that was nonsense. I convinced the team members that we don't need interfaces for ALL classes.

I tried to put this in my ant task:
Code:
<hbmtemplate
   filepattern="{package-name}/Base{class-name}.java"
   template="Pojo.vm"
/>


and I modified PojoConstructor to match to the new naming convention:

Code:
    /** default constructor */
    public Base$pojo.getDeclarationName()()
    {
    }


... but it doesn't work as expected. I get several warning from Velocity.

Code:
[hibernatetool] WARN   logVelocityMessage, org.apache.velocity.runtime.exception.ReferenceException: reference : template = TemplateHelper [line 93,column 9] : $pojo.getJavaTypeName($property, $jdk5) is not a valid reference.


For a table USERDATA I get one File called Userdata.java which looks ok. The file BaseUserdata.java is generated as well and looks like this:

Code:
public class BaseUserdata extends .... implements ... {

    // Fields   

     private $pojo.getJavaTypeName($field, $jdk5) id;
     private $pojo.getJavaTypeName($field, $jdk5) version;
     private $pojo.getJavaTypeName($field, $jdk5) orgEinheiten;
     private $pojo.getJavaTypeName($field, $jdk5) bearbKen;
...


Do I have to wait until beta status is finished or am I donig something wrong?

Rgds,
Axel

_________________
You'll never get a second chance to make a first impression!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 15, 2006 9:02 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
ah the wonders of configuration ;)

the issue is that the default pojo.vm assumes jdk5 and ejb3 is available...to work around that add <property> elements to make them available.

<hbmtemplate
filepattern="{package-name}/Base{class-name}.java"
template="Pojo.vm"
>
<property key="jdk5" value="false or true"/>
<property key="ejb3" value="false or true"/>
</hbmtemplate>

p.s. i'll make this more friendly soon ... so if they are not specified the templates will still work.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 15, 2006 9:21 am 
Beginner
Beginner

Joined: Thu Nov 25, 2004 7:07 am
Posts: 43
Location: Germany
max wrote:
ah the wonders of configuration ;)

the issue is that the default pojo.vm assumes jdk5 and ejb3 is available...to work around that add <property> elements to make them available.


I thought these properties will be taken from <hbm2java ... But now it should work as expected! Great! Many thanks.

_________________
You'll never get a second chance to make a first impression!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.