Skip to main content

JPA OneToMany not deleting child


i have a problem with a simple @OneToMany mapping between a parent and a child entity. All works well, only that child records are not deleted when i remove them from the collection.



The parent:




@Entity
public class Parent {
@Id
@Column(name = "ID")
private Long id;

@OneToMany(cascade = {CascadeType.ALL}, mappedBy = "parent")
private Set<Child> childs = new HashSet<Child>();

...
}



The child:




@Entity
public class Child {
@Id
@Column(name = "ID")
private Long id;

@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name="PARENTID", nullable = false)
private Parent parent;

...
}



If i now delete and child from the childs Set, it does not get deleted from the database. I tried nullifying the child.parent reference, but that did not work either.



The entities are used in a web application, the delete happens as part of an ajax request. I don't have a list of deleted childs when the save button is pressed, so i can't delete them implicitly.



Any pointers? Thanks in advance for your time


Source: Tips4all

Comments

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?