-->
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: set cascade=delete detaches removed set element
PostPosted: Wed Oct 10, 2007 6:10 am 
Newbie

Joined: Fri Mar 23, 2007 4:47 am
Posts: 16
Hi All

I have a Folder object. This folder object has children folders like this:

Code:
<set name="subFolders" cascade="delete" order-by="N">
    <key column="ParentFolderUUID" />

    <one-to-many class="com.myCompany.file.Folder" />
</set>


In my service layer I supply security. This means if a user may not view a sub folder the sub folder should be removed from the parent folder subFolder set. Like this:

Code:
if (noSecurity)
    parentFolder.getSubFolders().remove( subFolder);


If I do this, hibernate updates the subFolder in such a way that it is detached from the parent folder. The thing is, I have set cascade="delete". According to hibernate, cascade="delete" should only delete the sub folders when delete() is called on the parent folder. It shouldnt detach the subFolder in anyway when cascade is set to delete.

It's possible I have misunderstood how hibernate works. In that case, can anybody tell me how can I remove elements from a set or list without hibernate applying changes immediately to the database?

Thanks in advance,
Martyn


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 10, 2007 7:18 am 
Newbie

Joined: Fri Mar 23, 2007 4:47 am
Posts: 16
I have found the solution. I have added readOnly to my transaction manager for that specific method and now everything works perfectly.


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.