-->
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: ManyToOne Delete cascade unidirectional -Conclusion-
PostPosted: Thu Apr 12, 2007 10:16 am 
Newbie

Joined: Wed Apr 11, 2007 2:35 pm
Posts: 3
Hey,
I tried to get an very easy feature to run, but i was supprised
how many possibilities i found, and that at least only one worked.
A ChildClass has an ManyToOne reference to a ParantClass. When
the parent will be deleted, i want every child deleted as well. Thats
all. One possibility is of course, i delete all children myself an
delete than the parent. But i think Hibernate should handle this.

Code:
@Entity
public class Child {
   private Parent parent;

   @ManyToOne
   public Parent getParent() {...}
   public void setParent(..){..}
}

@Entity
public class Parent {
   private anything...
}


So there ist the possibility to use the JPI stuff like. In
class Child I did the following:

Code:
@ManyToOne (cascade = CascadeType.ALL)
public Parent getParent() {...}


Of course I tried CascateType.REMOVE and things like
that.
Does not work. OK, next try: This time i use the
Hibernate stuff.

Code:
@Cascade( value = CascadeType.ALL)
public Parent getParent() {...}


Of course I tried this DELETE_ORPHAN
Does not work. Ok, next Try: This time i use
another thing i found in the documentation:

Code:
@OnDelete(action = OnDeleteAction.CASCADE)
public Parent getParent() {...}


Does not work. Ok, next Try: If i say it is a unidirectional
relation, that means that i have to change the parent class.
Code:

@Entity
public class Parent {
private List<Child> children = new ArrayList...
    @OneToMany(cascade={ CascadeType.ALL},
                         fetch = FetchType.LAZY, 
                         mappedBy = "parent")
    public List<Child> getChildren() {...}
    public void setChildren(...)
}


This works fine, but this is not what i wanted. Are the features
not implemented? Any ideas ? What did i wrong?


Top
 Profile  
 
 Post subject: Re: ManyToOne Delete cascade unidirectional -Conclusion-
PostPosted: Fri Sep 04, 2009 3:21 pm 
Newbie

Joined: Fri Sep 04, 2009 3:13 pm
Posts: 3
Oh! I've been looking for the same problem solution for several days and still need it.
did anything chance for 2 years?


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.