-->
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.  [ 12 posts ] 
Author Message
 Post subject: Is there a way to add Cascade=All to the mapping file?
PostPosted: Thu Mar 20, 2008 11:37 pm 
Regular
Regular

Joined: Mon May 22, 2006 4:28 am
Posts: 56
Location: Göteborg, Sweden
Hi All,
I would like to be able to add cascade=All to my hbm.xml where I have one-to-many relations... I know I can do this manually or writing a Ant task that can search through the mapping files and add this... but I wonder if this is posible to do with Hibernate Tools? I am Using Hibernate Tools 3.2.0.GA

Thanks in advance,
Jacob


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 24, 2008 7:05 am 
Senior
Senior

Joined: Mon Feb 25, 2008 1:48 am
Posts: 191
Location: India
U can modify the .ftl files available inside the hibernate-tools.jar to suit your requirement. You can make almost any kind of change there to get your desired default behavior. Hibernate-tools.jar/hbm/many-to-one.ftl file would be a good place to start looking

_________________
Sukirtha


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 24, 2008 10:15 am 
Regular
Regular

Joined: Mon May 22, 2006 4:28 am
Posts: 56
Location: Göteborg, Sweden
Sukirtha wrote:
U can modify the .ftl files available inside the hibernate-tools.jar to suit your requirement. You can make almost any kind of change there to get your desired default behavior. Hibernate-tools.jar/hbm/many-to-one.ftl file would be a good place to start looking


Thanks for the answer,
I knew I can modify the template files, but I was more interested in a build in solution. In this thread from September 2006 Max said that at this time it doesn't exist, but might be added later...

http://forum.hibernate.org/viewtopic.ph ... ht=cascade

In this thread the user Arnon posted his solution where he in ant defined how to do this :

Quote:
<!-- Edit the HBM files for cascade attributes -->
<replaceregexp byline="true"
match="(set name=.billItems. inverse=.true.)"
replace="\1 cascade=&quot;all&quot;">
<fileset dir="${model.dir}/hbm">
<include name="Bill.hbm.xml"/>
<include name="BillLineItem.hbm.xml"/>
</fileset>
</replaceregexp>
<replaceregexp byline="true"
match="(many-to-one .* fetch=.select.)"
replace="\1 cascade=&quot;save-update,persist&quot;">
<fileset dir="${model.dir}/hbm">
<include name="BillItem.hbm.xml"/>
</fileset>
</replaceregexp>


But if you have a lot of tables this is really time consuming work...

Any updates on this Max?

Thanks in advance,
Jacob


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 24, 2008 6:37 pm 
Regular
Regular

Joined: Mon May 22, 2006 4:28 am
Posts: 56
Location: Göteborg, Sweden
Hi, I am looking in the many-to-on.hbm.ftl and I see this:

Quote:
<#if property.cascade != "none">
cascade="${property.cascade}"
</#if>


Where does this property.cascade come from and can I configure that property for each tables?

thanks for any pointers..
Jacob


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 25, 2008 12:05 am 
Senior
Senior

Joined: Mon Feb 25, 2008 1:48 am
Posts: 191
Location: India
Hi Jake,
"property" is passed into the many-to-one.ftl file by the calling .ftl file (In this case I guess it is persistentclass.ftl). So the calling .ftl file passes the property value to the called many-to-one.ftl file.

property.cascade holds the value for cascade based on the database table.

To achieve your purpose
Code:
<#if property.cascade != "none">
        cascade="${property.cascade}"
</#if>


can be changed to

Code:
<#if property.cascade != "none">
        cascade="all"
</#if>



Doing this will make all your many-to-one relations to have a cascade value set to "all" if the cascade is not explicitly set to none in the table.

_________________
Sukirtha


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 25, 2008 1:55 pm 
Hibernate Team
Hibernate Team

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

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 13, 2008 12:42 pm 
Newbie

Joined: Tue May 13, 2008 12:34 pm
Posts: 8
Location: Santiago de Chile
Hi

I have the some problem. I apply this solution but generated hbl.xml files don't have the property cascade="all" in the many-to-one elements.

I edit the hibernate-tools.jar included in my Hibernate Tools Eclipse plugin changing the many-to-one.ftl how Sukirtha explain, after remove all generated files (pojos, mapping and soa) and regenerated all files with the Hibernate Code Generator.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 14, 2008 3:06 am 
Senior
Senior

Joined: Mon Feb 25, 2008 1:48 am
Posts: 191
Location: India
Please post your build script.

1) Have you included the path of the customized .ftl files as the value for the templatepath attribute of the hibernatetools task?

2) where have you placed the modified .ftl files?

_________________
Sukirtha


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 14, 2008 4:39 am 
Senior
Senior

Joined: Mon Feb 25, 2008 1:48 am
Posts: 191
Location: India
Since you are using the pluggin, I am not sure how you add a reference to the modified .ftl files. The previous posts all dealt with ant scripts for code generation. Just make sure your pluggin uses the modified ftls.

_________________
Sukirtha


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 14, 2008 6:37 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you shouldnt be editing the templates inside the hibernatetools.jar.

Use template path - it is called that in the plugin AND in the ant scripts.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 14, 2008 3:10 pm 
Newbie

Joined: Tue May 13, 2008 12:34 pm
Posts: 8
Location: Santiago de Chile
Thanks max and Sukirtha, now understand more about the tools.

All references to templates in hibernate assumes use of ANT, and for now I only uses the eclipse plugin and the generator don't apply my template.

I create a directory called 'templates' in the basedir, then a file called many-to-one.ftl, a simple copy of the included file with the Sukirtha suggest changes. Finally, when run the code generator I activate the 'Use custom templates' check and set the template directory. I'm thinking in a missed step, because, where I set when my template was applied?

Please, any help is appreciate.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 14, 2008 5:35 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
did you remember to also keep the dir structure ?

<templatepath>/many-to-one.ftl is different from <tempaltepath>/hbm/many-to-one.ftl

/max

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