ObjectDB ObjectDB

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.

edit
delete
#2

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

ObjectDB Support
edit
delete

Reply

To post on this website please sign in.