-->
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.  [ 10 posts ] 
Author Message
 Post subject: Customize Reverse Engineering
PostPosted: Thu Apr 05, 2007 6:02 am 
Newbie

Joined: Thu Apr 05, 2007 5:29 am
Posts: 14
Location: France - Angers / Nantes
I'm searching for more information about reverse engineering and the customization possibility.

I read the Reference Guide (chap 5) about the reveng.xml file and Custom Strategy but there is not a lot of information about Custom Strategy.

#1 I would customize the hbm.xml generation (from database) and I'm not sure if a CustomReverseEngineeringStrategy can do that ?

In fact I don't want to use "wrapper classes" when I have composite-id in my database.
I want to delete the red part of this hbm.xml file
Code:
<composite-id [color=red]name="id" class="fr.gouv.finances.sp.cir.preliq.data.objetmetier.EnfId"[/color]>
    <key-property name="assNumeroCir" type="long">
        <column name="ASS_NUMERO_CIR" precision="11" scale="0" />
    </key-property>
    <key-property name="enfId" type="byte">
        <column name="ENF_ID" />
    </key-property>
</composite-id>


#2 Is that possible and How ? CustomStrategy ? reveng.xml ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 05, 2007 7:41 am 
Newbie

Joined: Thu Apr 05, 2007 5:29 am
Posts: 14
Location: France - Angers / Nantes
Where can I find the HBTools Javadoc ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 05, 2007 8:54 am 
Newbie

Joined: Thu Apr 05, 2007 5:29 am
Posts: 14
Location: France - Angers / Nantes
I tried in my CustomReverseEngineeringStrategy to override the classNameToCompositeIdName method in differents ways :

Code:
return null;

Gives me an "org.hibernate.tool.hbm2x.ExporterException" which does not astonish me.

Code:
return "";

Works but the "class" attribute of the "composite-id" element still in the hbm.xml. Empty but still here !

How can we say to hb tools not to create this f***ing class attribute :) ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 05, 2007 11:09 am 
Expert
Expert

Joined: Tue Jul 11, 2006 10:21 am
Posts: 457
Location: Columbus, Ohio
I'm afraid the composite key generation is a bit more complex than just overriding the classNameToCompositeIdName, which only changes the name of the composite id.

From a casual observation of the id.hbm.ftl template, if the class under inspection:

1) does not have an embedded identifier (true for all reverse engineering using the JDBCBinder as far as I can tell, only the HbmBinder has a facility to set the embedded flag on a component), and
2) the composite property is not a component

then it will fall through to the following Freemarker code in the id.hbm.ftl template:

Code:
    <composite-id
      name="${property.name}"
        class="${property.value.getComponentClassName()}"
<#if c2h.isUnsavedValue(property)>
        unsaved-value="${c2h.getUnsavedValue(property)}"
</#if>
<#if !property.basicPropertyAccessor>
        access="${property.propertyAccessorName}"
</#if>
    >      
    <#foreach keyproperty in property.value.propertyIterator>
     <#if !c2h.isManyToOne(keyproperty)>
           <key-property name="${keyproperty.name}" type="${keyproperty.value.typeName}">
           <#foreach column in keyproperty.columnIterator>
              <#include "pkcolumn.hbm.ftl">
           </#foreach>   
           </key-property>
     <#else>
         <key-many-to-one name="${keyproperty.name}" class="${c2j.getJavaTypeName(keyproperty, false)}">
            <#foreach column in keyproperty.columnIterator>
                <#include "pkcolumn.hbm.ftl">
            </#foreach>
           </key-many-to-one>
     </#if>
    </#foreach>
    </composite-id>   


It looks like the easiest way to do what you want is to modify the id.hbm.ftl Freemarker template, replacing the above code thusly:

Code:
    <composite-id
<#if c2h.isUnsavedValue(property)>
        unsaved-value="${c2h.getUnsavedValue(property)}"
</#if>
<#if !property.basicPropertyAccessor>
        access="${property.propertyAccessorName}"
</#if>
    >      
    <#foreach keyproperty in property.value.propertyIterator>
     <#if !c2h.isManyToOne(keyproperty)>
           <key-property name="${keyproperty.name}" type="${keyproperty.value.typeName}">
           <#foreach column in keyproperty.columnIterator>
              <#include "pkcolumn.hbm.ftl">
           </#foreach>   
           </key-property>
     <#else>
         <key-many-to-one name="${keyproperty.name}" class="${c2j.getJavaTypeName(keyproperty, false)}">
            <#foreach column in keyproperty.columnIterator>
                <#include "pkcolumn.hbm.ftl">
            </#foreach>
           </key-many-to-one>
     </#if>
    </#foreach>
    </composite-id>   


If you need some more information on how to accoplish this task, perhaps my post in this thread will help. Now I'm no expert in composite keys (never use them - we recently clean slated our existing tables and all new tables are 1st normal form), and perhaps Max would have more insight when he checks in, but at the least, this will work in the interim.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 06, 2007 3:07 am 
Newbie

Joined: Thu Apr 05, 2007 5:29 am
Posts: 14
Location: France - Angers / Nantes
So
*I extract the jar
*I modify the id.hbm.ftl
*I zip the directory and rename it to jar
*I run the Hibernate Code Generation (in Eclipse)

It don't seem to work ...
I checked, Eclipse uses the right jar !
I didn't find any error in console or error log view ...

Is there something else to do ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 06, 2007 4:13 am 
Newbie

Joined: Thu Apr 05, 2007 5:29 am
Posts: 14
Location: France - Angers / Nantes
I find the problem !
I modified the jar in my repository and not the jar in the eclipse plugin.

When I modify the hibernate-tools.jar in the eclipse\plugins\org.hibernate.eclipse_3.2.0.beta9\lib\tools directory, the hibernate tools plug-in no longer work ... :'(


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 06, 2007 4:48 am 
Newbie

Joined: Thu Apr 05, 2007 5:29 am
Posts: 14
Location: France - Angers / Nantes
ok,

I re-read your post and I copy the id.hbm.ftl in my project, I checked "Use Custom Templates"

and ...


I DID IT :)

Thx


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 07, 2007 3:28 am 
Hibernate Team
Hibernate Team

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

I always wonder why people try to go in and modify the jar's inside the eclipse plugins instead of seeing the "Custom templates" checkbox.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 10, 2007 3:53 am 
Newbie

Joined: Thu Apr 05, 2007 5:29 am
Posts: 14
Location: France - Angers / Nantes
max wrote:
I always wonder why people try to go in and modify the jar's inside the eclipse plugins instead of seeing the "Custom templates" checkbox.


I think that they simply don't see it :p !

Seriously, first times I try the hb tools plugin I wonder which was the goals of template, then I totally forgot this tiny check box. I think a comment about file generation (in bracket or something else) could help !
something like :
Hibernate Tools wrote:
Use Custom Templates (for custom file generation)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 10, 2007 5:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
ok - done that thing now. lets see if it helps ;)

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