Hi,
I unfortunately can't check every forum for every question every day so sometimes things slide through...i'll try and make a stab at this
megic wrote:
Hi,
I'm a newbie to Hibernate and I'm trying to figure how to modify the ReverseEngineeringStrategy to achieve customization of the generated code.
modifying reverse engineering strategy isn't really for newbies so I hope you are a bit more experience with hibernate than that ;)
Quote:
- Created CustomStrategy which extends DelegatingReverseEngineeringStrategy
- Appended "Entity" to all table class names using an override on .tableToClassName(TableIdentifier tableIdentifier)
- Set the identifier strategy to "native" using an override on .getTableIdentifierStrategyName(TableIdentifier tableIdentifier)
- Translated all PK column names to "id" using an override on .columnToPropertyName(TableIdentifier table, String column)
you are on a roll ;)
Quote:
And here's my wish list / questions that I can't figure out how/whether I can:
- Debug the reverse engineering / set break points to debug how my custom ReverseEngineeringStrategy works / what it does?
To do this you would need to either use Ant in debug mode and connect a debugger or run eclipse in debug mode and connect a separate instance to it.
Quote:
At least add custom logging (either to System.out or log4j)? I tried both and I don't seem to be able to find any output anywhere.
If you dont see any output i'll assume you are using the eclipse plugins and not the ant tasks. The logging goes to the error log view all controlled by log4j.properties in the hibernate plugins; and if you use system.out it should go to standard out of eclipse which should be visible if you run eclipse with -debug or -console.
Quote:
Generate all FKs with "lazy" fetching. Right now I have "select" everywhere.
select *is* lazy.
Quote:
Distinguish between Views and Tables, in particular append "Entity" to every class based on a table (done that already) and "View" to every class based on a view.
That information is not directly available. Hibernate's metamodel doesn't really have that distinguished. You'll need to query the database for that info or somehow be able to recognize that by some other means (i.e. naming)
Quote:
Teach Hibernate not to make up composite PKs for database views.
You simply then just need to provide a primary key it should use - use reveng.xml for that or implement getPrimaryKeyColumnNames to make a better suggestion.
Quote:
Make Entity classes implement one interface (e.g. HibernateEntity), and View classes implement another one (HibernateView). I would create these interfaces on my own.
Why ?
Anyway - implement tableToMetaAttributes and you can tell which interfaces/classes there should be extended. See hibernate tools docs on which attributes to use.
Quote:
Make Entity classes extend one class (e.g. HibernateEntityImpl), and View classes extended another one (e.g. HibernateViewImpl). I would create these classes on my own and provide some basic functionality.
See above.
Quote:
Make each class have a constructor that takes values for all properties (but not many-to-one relationships)
hmm - thats tricky; but this is not part of reverse engineering - that is part of code generation.
If the current minimal and full constructors does not cut if for you then you probably need to have a custom pojo/PojoConstructors.ftl template
and have it do or call out to your own utility class that figures out which fields you want included.
Quote:
Enable "dynamic-insert" and "dynamic-update" on all tables
Not directly supported in reverse engineering. If you really need that then you'll need to force than in the templates for hbm.xml or pojo's.
Quote:
Have an enumeration of field names/properties in every class (e.g. called "public enum Fields")
that's a very bad design IMO. just use reflection if you really need that.
Or if you really want that metadata statically available and possibly changing between releases and leaking into your layers then
generate a separate class/enum with this information. Simply have an additional hbm2java generation that uses your custom template and
not the default one that generate entities.
Quote:
Have a list/hashmap of properties on top of the "single properties" (getters, setters)
I don't undrestand what this is - but I think my answer would be the same as the previous one.
Quote:
Have a clone method that automatically assigns all properties from one object to anotherSounds *very* dangerous - be sure you don't just assign associations and collections blindly and accidentally mix up objects from different sessions or object graphs.
Quote:
I understand that I can control a lot through the
.hbm <meta> attributes. But I don't quite understand how can set those attributes through the ReverseEngineeringStrategy.
implement (table|column)ToMetaAttributes.
p.s. i'll be faster to react to such questions if answer on JBoss Tools forum ;)
Thanks in advance![/quote]