-->
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: Problem with removing children from a relationship OneToMany
PostPosted: Fri Oct 08, 2010 3:52 pm 
Newbie

Joined: Fri Oct 08, 2010 3:40 pm
Posts: 1
Gentlemen, I have a question (Forgive me for bad english I'm Brazilian).

I am using Hibernate and saving an object (Father) that has a Set <> another object (Son)

Imagine the following situation: I made a saveUpdate of a father with three children. Saved perfectly! Then I made a saveUpdate that same Father, but with only two children. The third son is still on the table.

Could anyone help me? I'm already using CascadeType.DELETE_ORPHAN

Below is the POJO's code:
Code:
@Entity 
@Table(name = "Father") 
public class Father implements java.io.Serializable { 
   
     private Integer idFather; 
     private String name; 
     private String description; 
     private Set<Son> sons = new HashSet<Son>(0); 
   
     @OneToMany(cascade = {CascadeType.PERSIST, 
                           CascadeType.MERGE, 
                           CascadeType.REMOVE}, fetch = FetchType.LAZY, mappedBy = "father") 
     @org.hibernate.annotations.Cascade (value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN) 
     public Set<Son> getSons() { 
         return this.sons; 
     } 
   
     //others get's e setter's 
}

Code:
@Entity 
@Table(name = "Son") 
public class Son implements java.io.Serializable { 
 
    private Integer idSon; 
    private Father father; 
    private String name; 
    private String description; 
 
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "idFather", nullable = false)
    public Father getFather() {
        return this.father;
    }

    //others get's e setter's 
}


Top
 Profile  
 
 Post subject: Re: Problem with removing children from a relationship OneToMany
PostPosted: Fri Oct 08, 2010 10:46 pm 
Regular
Regular

Joined: Sun Feb 14, 2010 3:29 pm
Posts: 58
Location: USA
how do you remove the "son"?

saveUpdate is used when you are working with dettached object, is that what you have?

_________________
Zemian Deng
------------
Need a Java Scheduler? Try
http://bitbucket.org/timemachine/scheduler


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.