-->
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: deletin of an object by way of recursion
PostPosted: Fri Apr 11, 2008 2:58 pm 
Newbie

Joined: Fri Apr 04, 2008 1:54 am
Posts: 3
Hi,

I am trying to delete an object that has pointers to other objects which have pointers to it. Im doing this recursively, such that:

object A has 3 children in a collection (objects A1, B1, and C1) each with a pointer to it. Object A tries to delete itself but before it can it instructs object A1, B1, and C1 to delete themselves. Objects A1, B1, and C1 eventually completely orpahn themselves and are passed to em.remove() and even a call to em.flush() and theres no problem. Now, the recursion has tailed off and were back at the call site -- object A. i want to delete object A and finish the loop. I call em.remove( ) on A and even em.flush() to provke the exception which is its complaining that Im passing a deleted instance of the type that objects A1, B1, and C1 were. (deleted entity passed to persist (Type#null), etc..)

I can see that as I call em.remove() theres _NOTHING_ hanging onto A. ans A1, B1, and C1 made it past the calls to remove. How can I detect or debug saomething like this? Is there an internal hibernate mechanism (say in the HibernateProxy stuff or the ClassMetadata?) that i can use to determine if something is deleted?

Thanks in advance for any help!

_________________
Josh Long
Sun Certified Java Programmer
http://www.joshlong.com


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 11, 2008 3:46 pm 
Newbie

Joined: Fri Apr 04, 2008 2:17 pm
Posts: 15
I think what you want is cascading deletes, isn't it?

So if I have a class Group that has a collection of GroupMembers then I want every GroupMember to be deleted upon deleting the Group.

So my classes look something like...

Code:
...
import javax.persistence.*;
import java.util.*;

@Entity
@Table(name="GROUPS")
public class Group{
   ...
   @OneToMany(mappedBy="group", cascade=CascadeType.ALL)
   private Set<GroupMember> members = new HashSet<GroupMember>();
   ...


Code:
...
import javax.persistence.*;

@Entity
@Table(name="GROUP_MEMBERS")
public class GroupMember{
   ...
   @ManyToOne
   @JoinColumn(name="GROUP_ID")
   private Group group;
   ...


So the parent points to the child and the child points to the parent. But it's the parent that has a special annotation on it to get the desired behavior.

Is this along the lines of what you're looking for?


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.