Hi,
I can't figure this out and I hope someone out there has.
Code:
class Parent {
@OneToMany(mappedBy="parent")
private List<Child> children;
void addChild(Child c) {
c.setParent(this);
getChildren().add(c);
}
}
class Child {
@ManyToOne
private Parent parent;
}
{
Parent p = findById(4);
p.addChild(childService.findById(7));
p.addChild(childService.findById(8));
update(p);
delete(p);
}
If I have no cascade set on the parent's annotation, I get a FK error. If I set cascade delete, it deletes the parents children - which I do not want.
I want the children to remain in the db for later. So, the call to delete should null out the parent column on each child. Obviously I could subclass my hibernate thing and put a for loop in there to do that, but there's got to be a way to
@OnDelete(action=OnDelete.SET_NULL) ?
instead of
Code:
class ParentService extends Service<Parent> {
@Override
void delete(Parent p) {
for (Child c : p.getChildren) {
c.setParent(null);
childService.update(child);
}
}
Any ideas? TIA