-->
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: Cascade delete: How to delete association but not object?
PostPosted: Tue Nov 02, 2010 11:34 am 
Newbie

Joined: Fri Sep 04, 2009 8:24 am
Posts: 5
I have three tables: MENU, PERMISSION, and MENUPERMISSION. MENU contains menu options for a website, PERMISSION contains permissions users can possess, and MENUPERMISSION simply has columns MENUID and PERMISSIONID to represent the association of a certain permission with a certain menu option.

I want to create a many-to-many relationship in the PERMISSION hbm that will cascade delete to MENUPERMISSION but not MENU. That way when the admin user deletes a permission, all rows in MENUPERMISSION with the given PERMISSIONID will be deleted, but the associated MENU objects themselves will not be deleted. I've tried this:

Code:
<set name="menusAssociatedWithPermission" table="MENUPERMISSION" cascade="delete">
   <key column="PERMISSIONID"/>
   <many-to-many class="Menu" column="MENUID"/>
</set>

I've tried it with cascade="delete", cascade="delete-orphan", and cascade="all,delete-orphan", and each time, all relevant objects from all three tables (including MENU) get deleted. What am I doing wrong?

Thanks,
Erica


Top
 Profile  
 
 Post subject: Re: Cascade delete: How to delete association but not object?
PostPosted: Tue Nov 02, 2010 1:28 pm 
Newbie

Joined: Fri Sep 04, 2009 8:24 am
Posts: 5
I think I may have fixed it using cascade="none". It seems like that successfully deletes the associated MENUPERMISSION row when I delete a permission, without also deleting the MENU object the permission was previously associated with. Does that make sense?


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.