-->
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.  [ 5 posts ] 
Author Message
 Post subject: cascade = CascadeType.ALL not deleting
PostPosted: Mon Nov 27, 2006 10:39 pm 
Beginner
Beginner

Joined: Wed Apr 06, 2005 9:29 pm
Posts: 24
Hibernate version: 3.2.0GA
Annotations: 3.2.0GA

DB: MySQL

I have a Set of "Preferences" contained in a "Recipient". If I delete the recipient or when I add Preferences everything is fine. When I remove Prefs from the Set they are not deleted. Any thoughts?

Thanks,
John

@Entity
@DiscriminatorValue( "RECIPIENT" )
public class Recipient extends Person {
...

@OneToMany( mappedBy = "recipient", cascade = CascadeType.ALL )
private Set<Preference> preferences = new HashSet<Preference>();

...
}

@Entity
public class Preference implements Serializable {
...

@ManyToOne
private Recipient recipient;

...
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 28, 2006 2:14 am 
Regular
Regular

Joined: Tue May 16, 2006 3:32 am
Posts: 117
You need to add org.hibernate.annotations.CascadeType.DELETE_ORPHAN for the required behaviour.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 29, 2006 12:17 am 
Beginner
Beginner

Joined: Wed Apr 06, 2005 9:29 pm
Posts: 24
Man,
That was perfect. The exact answer I needed.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 30, 2006 5:32 am 
Newbie

Joined: Fri Jun 17, 2005 2:07 am
Posts: 19
Location: Berne, Switzerland
hi,

DELETE_ORPHAN is a proprietary feature of Hibernate and is not available in other JPA-implementations. you'd better delete the object manually after removing it from the set.

jakob


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 01, 2006 12:25 am 
Beginner
Beginner

Joined: Wed Apr 06, 2005 9:29 pm
Posts: 24
brj wrote:
hi,

DELETE_ORPHAN is a proprietary feature of Hibernate and is not available in other JPA-implementations. you'd better delete the object manually after removing it from the set.

jakob


Well, I consider that a failing of the group that created JPA. In my estimation
the job of Hibernate or any persistence infrastructure is to make persistence
transparent as possible. With Hibernate it is, apparently. When I remove an
Object from a list expecting it to be garbage collected, I should be able to let
the persistence infrastructure mirror that change in the DB. The list is another
good example in my mind. JPA has some sort of ordering annotation. Here is
a crazy idea, how about you just give me the list I told you to store in the
order it was in. Hibernate can to it. Again it is proprietary, but that is more a
sad commentary about the guys the made JPA than on Hibernate. I don't see
a good reason to avoid doing things the simple logical way when you can
use Hibernate in any environment. Sorry for the blast, but there is a reason
Hibernate is taking over the world. They built a better mouse trap.

John


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