-->
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.  [ 4 posts ] 
Author Message
 Post subject: How Cascade delete_orphan works?
PostPosted: Mon Jan 07, 2008 1:37 am 
Newbie

Joined: Wed Dec 12, 2007 3:04 pm
Posts: 9
Hello,

I have a web application(Hibernate) where users can drag and drop HTML elements like (text field,label, buttons) and save it. I use saveorupdate function.
I have parent-child relationship through one-to-many associations. I am using annotations.

1:m
Page<--Widgets

I am doing
@OneToMany( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN})


My problem,

--Assume user saves 3 widgets(textfield,label, button), it perfectly saves. Now the user loads back the same data and deletes the button and saves, now there is only 2widgets(textfield,label).

The problem is now the button still exists in the database, I was hoping that cascade.DELETE_ORPHAN will deleted the non-referenced record.

so is that my understanding is wrong or this can't be done this way.

So alternative solution i was thinking was
-- delete everything and just do a new save.

so is there is any better solutions?


~Pen


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 07, 2008 4:27 am 
Beginner
Beginner

Joined: Thu Nov 15, 2007 11:27 am
Posts: 34
I'm not used of annotation, but the cascade delete orphan do the job, assuming, you remove the elements from the collection using a collection.clear() ( or .remove(object) ).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 09, 2008 1:23 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
You're going to have to post some code, DELETE_ORPHAN should work provided that you're not replacing the collection with a new one at some point.

_________________
Some people are like Slinkies - not really good for anything, but you still can't help but smile when you see one tumble down the stairs.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 17, 2008 1:53 am 
Newbie

Joined: Wed Jan 16, 2008 2:22 am
Posts: 4
I think I have the same problem as you,
http://forum.hibernate.org/viewtopic.php?t=982865

You found a solution for your problem


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.