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_ORPHANBelow 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
}