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