-->
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.  [ 2 posts ] 
Author Message
 Post subject: How add .hbm.xml to reveng.xml session?
PostPosted: Sat Feb 18, 2012 5:05 am 
Beginner
Beginner

Joined: Tue Oct 20, 2009 6:28 am
Posts: 20
Hello,

I need to add some custom/already generated .hbm.xml to the reveng.xml session.

Currently I do something like:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >

<hibernate-reverse-engineering>
   <schema-selection match-schema="public" />
   <type-mapping>
      <sql-type jdbc-type="BIGINT" hibernate-type="java.lang.Long" />
      <sql-type jdbc-type="INTEGER" hibernate-type="java.lang.Integer" />
   </type-mapping>


   <table-filter match-name="lead" match-schema="public" exclude="false" />
   <table-filter match-name="contact_.*" match-schema="public" exclude="false" />
      
   <table name="contact_record">
      <primary-key>
         <generator class="sequence">
            <param name="table">contact_record_id_contact_record_seq</param>
         </generator>
      </primary-key>
   </table>

   <table name="contact_record_data">
      <primary-key>
         <generator class="sequence">
            <param name="table">contact_record_data_id_contact_record_data_seq</param>
         </generator>
      </primary-key>
   </table>

   <table name="contact_type">
      <primary-key>
         <generator class="sequence">
            <param name="table">contact_type_id_contact_type_seq</param>
         </generator>
      </primary-key>
   </table>

   <table name="contact_type_category">
      <primary-key>
         <generator class="sequence">
            <param name="table">contact_type_category_id_contact_type_category_seq</param>
         </generator>
      </primary-key>
   </table>



   <table name="contact_life_cycle">
      <primary-key>
         <generator class="sequence">
            <param name="table">contact_life_cycle_id_contact_life_cycle_seq</param>
         </generator>
      </primary-key>
   </table>


   <table name="contact_life_cycle_category">
      <primary-key>
         <generator class="sequence">
            <param name="table">contact_life_cycle_category_id_contact_life_cycle_category_seq</param>
         </generator>
      </primary-key>
   </table>


   <table name="contact_life_cycle_data">
      <primary-key>
         <generator class="sequence">
            <param name="table">contact_life_cycle_data_id_contact_life_cycle_data_seq</param>
         </generator>
      </primary-key>
   </table>

   <table name="contact_life_cycle_status">
      <primary-key>
         <generator class="sequence">
            <param name="table">contact_life_cycle_status_id_contact_life_cycle_status_seq</param>
         </generator>
      </primary-key>
   </table>

</hibernate-reverse-engineering>




And works right because the table contact_record got it's foreign key recognized:

Code:
<hibernate-mapping>
    <class name="com.level2.enterprise.hibernate.generated.ContactRecord" table="contact_record">
        <id name="idContactRecord" type="java.lang.Integer">
            <column name="id_contact_record" />
            <generator class="sequence">
                <param name="table">contact_record_id_contact_record_seq</param>
            </generator>
        </id>
        ...
        <many-to-one name="lead" class="com.level2.enterprise.hibernate.generated.Lead" fetch="select">
            <column name="uuid" not-null="true" />
        </many-to-one>
        <many-to-one name="contactType" class="com.level2.enterprise.hibernate.generated.ContactType" fetch="select">
            <column name="id_contact_type" not-null="true" />
        </many-to-one>
        <property name="idShop" type="java.lang.Integer">
            <column name="id_shop" />
        </property>
         ...
    </class>
</hibernate-mapping>


But this class "Lead" was generated in another package so I have to remove manually.

Also the column idShop has a foreign key to another column that's not present in the reveng.xml file because as Lead is already generated.

The question is:

How can I add the already generated classes to the reveng.xml configuration or eclipse configuration?

I want to add the .hbm.xml files so it has everything to work with without the need of adding actual tables to reveng environment.


Thank you in advance.


Top
 Profile  
 
 Post subject: Re: How add .hbm.xml to reveng.xml session?
PostPosted: Wed Feb 29, 2012 8:06 am 
Senior
Senior

Joined: Fri May 08, 2009 12:27 pm
Posts: 168
I don't think that's possible.

My experience with Hibernate Tools in general has been mixed.
It's a challenging mental puzzle to make all the pieces work together: making reveng guess all the metadata right and find what details you need to provide; wrap your head around reveng's data type configuration, DelegatingReverseEngineeringStrategy, and templates; all of this using woefully incomplete documentation (which are getting better but are still far from even adequate).
I got everything sorted out well enough that reveng works for me, but that has been a process of two years and involved a lot of yelling, hair-pulling, googling, rejecting obsolete advice, and single-stepping into Hibernate sources (the latter more in Hibernate than Hibernate Tools, though).
And the result still isn't pretty. I have configuration data scattered all over the place: central points like hibernate.reveng.xml, a hand-crafted DelegatingHibernateRevenStrategy, overrides for six files in the templates supplied with Hibernate Tools (which means I need to check all six for mergeworthy changes whenever I upgrade Tools), .hbm.xml files that are partly overwritten and partly kept, a hibernate.xml that's partly overwritten and partly kept, plus a business logic class for each generated entity class. Everything depends on everything; I hope no woodpecker comes along.

If I were to do this again, I'd ignore Hibernate Tools and reveng, and simply configure the Hibernate session factory with hibernate.hbm2ddl.auto=validate, to make Hibernate check whether its annotation-supplied data model is consistent with the database metadata. (That test could be done in unit tests or at application startup, whatever rocks the boat.)
And I'd do the reveng manually, using annotations. I'm annotating entity attributes with information like validation rules, and what's the best Swing component to render or edit a value from or for that attribute, and all these things depend on the DB representation type (you don't want a NumberFormatter on something that maps to a VARCHAR column), so I need to look that information up anyway, and including the information that Reveng would provide isn't that much of a burden anymore. YMMV.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.