-->
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: Reverse ingeneering, cascade strategy
PostPosted: Tue Nov 18, 2008 5:10 am 
Newbie

Joined: Mon Jul 30, 2007 1:59 pm
Posts: 6
Hi,

I use Hibernate Tools in reverse ingeneering to generate my annotated Pojo from a MySQL database. I would like to change the cascade elements, Hibernate Tools generates :
Code:
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "INT_IDENTIFIANT", unique = true, nullable = false, insertable = false, updatable = false)
    public Affaire getAffaire() {
        return this.affaire;
    }


but I would like to have :
Code:
    @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinColumn(name = "INT_IDENTIFIANT", unique = true, nullable = false, insertable = false, updatable = false)
    public Affaire getAffaire() {
        return this.affaire;
    }


How can I for Hibernate Tools to generate the cascade element, the only solution I found is to add ant Ant task with regular expressions but if I can avoid it ;) ? I looked about the "columnToMetaAttributes" method from DelegatingReverseEngineeringStrategy but I didn't find documentation about, it seems there is no MetaAttribute about this kind of annotation.

Thanks,
Jean-Claude


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 19, 2008 7:09 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
we don't have a good way to fine grain control the cascade's.

Look in reveng.xml docs on which options we can control.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 04, 2009 4:56 am 
Newbie

Joined: Wed Feb 04, 2009 4:33 am
Posts: 1
This is the solution I use:

I changed the file Ejb3PropertyGetAnnotation.ftl of hibernateTools. I added
the line "@org.hibernate.annotations.Cascade
({org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.MERGE})" and "${property.setCascade("MERGE")}"
to generate the cascade element:
Code:
...
<#if c2h.isManyToOne(property)>
<#--TODO support @OneToOne true and false-->   
${pojo.generateManyToOneAnnotation(property)}
@org.hibernate.annotations.Cascade
({org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.MERGE})
<#--TODO support optional and targetEntity-->   
${pojo.generateJoinColumnsAnnotation(property, cfg)}
<#elseif c2h.isCollection(property)>
${property.setCascade("MERGE")}
${pojo.generateCollectionAnnotation(property, cfg)}
<#else>
${pojo.generateBasicAnnotation(property)}
${pojo.generateAnnColumnAnnotation(property)}
</#if>
...


This is an example of the code that hibernateTools generates with the changes I've made:
Code:

   @ManyToOne(fetch = FetchType.LAZY)
   @org.hibernate.annotations.Cascade( {
         org.hibernate.annotations.CascadeType.SAVE_UPDATE,
         org.hibernate.annotations.CascadeType.MERGE })
   @JoinColumn(name = "ALLERGEN_TYPE_CODE_FK")
   public Cat0127AllergyType getCat0127AllergyType() {
      return this.cat0127AllergyType;
   }
...

   @OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY, mappedBy = "segAl1")
   public Set<SegRelAl1> getSegRelAl1s() {
      return this.segRelAl1s;
   }


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.