-->
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.  [ 8 posts ] 
Author Message
 Post subject: Determine sub-class strategy
PostPosted: Tue Feb 13, 2007 5:29 am 
Hi,

I've got a couple of projects that use the hbm2java ant task to generate EJB3 entities from hibernate mapping files.

One project uses only table-per-class-hierarchy for sub-classes, the other exclusively uses table-per-sub-class.

I've started tidying up the code in this area but I've got a bit stuck trying to determine from the PersistentClass I get in the template generation which inheritance strategy applies...

Anyone any suggestions?

Thanks

Andy


Top
  
 
 Post subject:
PostPosted: Tue Feb 13, 2007 7:21 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
the type of PersistentClass can be used for it...but probably safer to look at how the SessionFactoryImpl decides to create the different persisters based on the Configuration data.....you can also look in HbmBinder to see what the different tags gets bound too - and use that info in the templates.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 13, 2007 7:54 am 
Hi + thanks for the reply.

I don't have an instance of SessionFactoryImpl to hand - perhaps I should explain a bit more about what I'm trying to do:

Basically, I am trying to make the code used to generate annotations in hbm2java pluggable, along the lines that a RevEngStrategy makes descisions about reverse engineering from a db pluggable.

This is driven by my experience over the last 4 months where 2 different projects for two completely seperate customers have wanted to generate EJB3 entities from .hbm.xml maping files...

In each case, we ended up checking out the hibernate-tools project and "mangling" EntityPOJOClass.java to change or extend the strings created for annotation values (default cascade options, lazy load as default, version property etc) and rebuilding hibernate-tools.jar...

It strikes me that this is really not the way to do it.

So, as somthing to keep me occupied in the hotel bar last night I had a go at creating my own extension of HibernateToolTask.java which accepted a nested element for my own PluggableAnnotationGeneratorPojoExporter (extends from POJOExporter) which puts an instance of a configurable imlementation of my Ejb3EntityAnnotationBuilder interface into the same context as the "pojo" variable for .ftl templates. Finally I altered Ejb3TypeDeclaration.ftl to use my annotation builder rather than using pojo.whatever() direct.

It all hangs together :) - its a bit long-winded but it means I havent changed any hibernate classes...

Where I ground to a halt was using the PersistentClass returned by pojoClass.getDecoratedObject() to determine what kind of inheritance was going on in the entities and therefore what inheritance strategy annotations to include - any thoughts?

Cheers,

Andy


Top
  
 
 Post subject:
PostPosted: Tue Feb 13, 2007 8:14 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
andyredhead wrote:
Hi + thanks for the reply.

I don't have an instance of SessionFactoryImpl to hand - perhaps I should explain a bit more about what I'm trying to do:


I did not say you needed an instance of SessionFactoryImpl; I said that you could look in the code that is has to decide what persister to create....its the same info you need.

Quote:
Basically, I am trying to make the code used to generate annotations in hbm2java pluggable, along the lines that a RevEngStrategy makes descisions about reverse engineering from a db pluggable.


I agree that a strategy might be relevant for hbm2java - but I don't agree that deciding which inheritance strategy is something hbm2java should care about...that is the job of the reverse engineering.

remember that hbm2java just needs to "dump" the existing hbm model - not try and redo/rebuild it.

Quote:
This is driven by my experience over the last 4 months where 2 different projects for two completely seperate customers have wanted to generate EJB3 entities from .hbm.xml maping files...


yes..and here the inheritance is set in stone. (the mapping states what the inheritance is, right ?)

Quote:
In each case, we ended up checking out the hibernate-tools project and "mangling" EntityPOJOClass.java to change or extend the strings created for annotation values (default cascade options, lazy load as default, version property etc) and rebuilding hibernate-tools.jar...

It strikes me that this is really not the way to do it.


no - it aint ;)

[qote]
So, as somthing to keep me occupied in the hotel bar last night I had a go at creating my own extension of HibernateToolTask.java which accepted a nested element for my own PluggableAnnotationGeneratorPojoExporter (extends from POJOExporter) which puts an instance of a configurable imlementation of my Ejb3EntityAnnotationBuilder interface into the same context as the "pojo" variable for .ftl templates. Finally I altered Ejb3TypeDeclaration.ftl to use my annotation builder rather than using pojo.whatever() direct.

It all hangs together :) - its a bit long-winded but it means I havent changed any hibernate classes...
[/quote]

I still don't get why you want hbm2java to generate something different than what is simply mapped ;)

Quote:
Where I ground to a halt was using the PersistentClass returned by pojoClass.getDecoratedObject() to determine what kind of inheritance was going on in the entities and therefore what inheritance strategy annotations to include - any thoughts?


look in HbmBinder and/or SessionFactoryImpl to find the logic.....

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 13, 2007 8:20 am 
Quote:
I did not say you needed an instance of SessionFactoryImpl; I said that you could look in the code that is has to decide what persister to create....its the same info you need.


Ah, gotit - I'll go and read the code.

I'm not changing the inheritance defined by the mapping files, just trying to reflect the mappings in the generated annotations - hbm2java for entities didn't generate the annotations for either table-per-subclass or table-per-hierarchy, at least not in the version I was using. Perhaps it does now, I'll go and check...

Thanks,

Andy


Top
  
 
 Post subject:
PostPosted: Tue Feb 13, 2007 8:26 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
ah ok - I just got "thrown off" because you said reveng from db and have hbm2java to generate the apropriate inheritance....which is kinda impossible since reveng from db does not do inheritance ;)

jpa annotations might very well not generate proper annotations code - would be great to get that ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 13, 2007 8:30 am 
The overall scheme I've been using is reverse engineer from db to hibernate mapping files once then manually adjusting the mappings to include inheritance, toString/equals properties etc and then generating the entities from there.

I'll let you know how I get on. I'll be quite happy to contribute it if it turns out to be useful :)


Top
  
 
 Post subject:
PostPosted: Tue Feb 13, 2007 9:02 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
cool.

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