-->
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: Controlling Cascade
PostPosted: Fri Feb 16, 2007 1:53 am 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
Hi,

I've read several post about controlling the cascade type while reverse engineering and the answer seems to be "not doable yet".

Is this still the case?
Has anybody found a good way yet?

I basically need to set the default cascade type for certain types of relationships (many-many, many-one, etc).

Thanks in advance.

Budyanto


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 16, 2007 4:43 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
only currenlty doable by tweaking the templates

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 16, 2007 10:07 am 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
Thats good enough.

Can you say more Max? I need it for the POJOs by the way.

Budyanto


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 16, 2007 2:13 pm 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
I see one that suggests doing this in hibernate-mapping.hbm.xml.ftl

Code:
<#else>
<hibernate-mapping default-cascade="save-update" >
</#if>


However this will set the cascade for all relationship types.

Budyanto


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 16, 2007 5:47 pm 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
I managed to do it this way.

Modify Ejb3PropertyGetAnnotation.ftl

Code:
<#elseif c2h.isCollection(property)>
<!-- The following line is added to control cascade -->
${property.setCascade("persist,merge")}
${pojo.generateCollectionAnnotation(property, cfg)}
<#else>

Budyanto


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 16, 2007 7:06 pm 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
Actually the above soluton "sorta work". The problem is ManyToMany and OneToMany seems to be controlled within the same if clause. (the isCollection(property)).

Is there a way to separate the two? I'd like to set the ManyToMany cascade to "persists,merge" and OneToMany to "all".

Thanks
Budyanto


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 16, 2007 8:42 pm 
Senior
Senior

Joined: Sat Aug 19, 2006 6:31 pm
Posts: 139
I seem to be answering my own questions.

I was able to do it this way.

Code:
   <#elseif c2h.isCollection(property)>
      ${property.setCascade("persist,merge")}
      <#if c2h.isOneToManyCollection(property)>
         ${property.setCascade("all")}
      </#if>
      ${pojo.generateCollectionAnnotation(property, cfg)}
   <#else>


Top
 Profile  
 
 Post subject: Controlling cascade
PostPosted: Sat Mar 10, 2007 2:54 am 
Beginner
Beginner

Joined: Mon Aug 15, 2005 9:00 pm
Posts: 37
Max,

Which template and how to tweak it? my project is stuck on this issue when using the tool to generate hbm.xml for hundreds of tables - manually changing hundreds of hbm.xml is not an option - given table definition also change from time to time.

Budyanto, where are these *.ftl ?


Thanks In Advance
chuck


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 10, 2007 4:30 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hibernate-tools.jar/hbm/*.ftl

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 11, 2007 2:54 am 
Beginner
Beginner

Joined: Mon Aug 15, 2005 9:00 pm
Posts: 37
Here is what works for me:

add to plugins\org.hibernate.eclipse_3.2.0.beta9a\lib\tools\hibernate-tools.jar/hbm/set.hbm.ftl

<#if c2h.isOneToMany(property)>
cascade="all-delete-orphan"
<#else>
cascade="persist-merge"
</#if>


Thx
Chuck


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.