-->
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: Customize ReverseEngineeringStrategy
PostPosted: Fri Jan 21, 2011 12:16 pm 
Newbie

Joined: Fri Dec 10, 2010 11:52 am
Posts: 3
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.

Here's what I've done so far:

  • 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)

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?
  • 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.
  • Generate all FKs with "lazy" fetching. Right now I have "select" everywhere.
  • 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.
  • Teach Hibernate not to make up composite PKs for database views.
  • Make Entity classes implement one interface (e.g. HibernateEntity), and View classes implement another one (HibernateView). I would create these interfaces on my own.
  • 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.
  • Make each class have a constructor that takes values for all properties (but not many-to-one relationships)
  • Enable "dynamic-insert" and "dynamic-update" on all tables
  • Have an enumeration of field names/properties in every class (e.g. called "public enum Fields")
  • Have a list/hashmap of properties on top of the "single properties" (getters, setters)
  • Have a clone method that automatically assigns all properties from one object to another

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.

Please let me know.

Thanks in advance!


Top
 Profile  
 
 Post subject: Re: Customize ReverseEngineeringStrategy
PostPosted: Mon Feb 14, 2011 11:40 am 
Newbie

Joined: Fri Dec 10, 2010 11:52 am
Posts: 3
Is there really nobody who can provide any feedback on any of the questions above? :(


Top
 Profile  
 
 Post subject: Re: Customize ReverseEngineeringStrategy
PostPosted: Tue Feb 15, 2011 7:48 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
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 another


  • Sounds *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]

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