Removing an element from an @OneToMany doesn't work

#1

Hello. I have a Parent and Child entities.

// in the parent

@OneToMany(mappedBy = "parent", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private List<Child> children;

// in the child

@ManyToOne
private Parent parent;

Somewhere I do this:

parent.getChildren().remove(0);
manager.merge(parent);

Manager.merge is just

transaction.begin();
entityManager.merge(o);
transaction.commit();

But the element isn't removed. Should I remove the children entity too? It works using EntityManagerFactory.

#2

You should update both sides, i.e. set null in the child's parent field.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply

To post a reply and/or subscribe to update notifications - please login