Hi
I have an entitity with a following mapping:
Code:
@OneToMany(cascade=CascadeType.ALL, fetch = FetchType.EAGER)
@Cascade( { org.hibernate.annotations.CascadeType.ALL, org.hibernate.annotations.CascadeType.DELETE_ORPHAN } )
@IndexColumn(name = "position", base = AppInfo.BASE)
@JoinColumn(name="parent", nullable=false)
private List<MenuItem> children;
public List<MenuItem> getChildren() {
return children;
}
public void setChildren(List<MenuItem> children) {
this.children = children;
}
@ManyToOne()
@JoinColumn(name="parent", insertable=false, updatable=false, nullable=false)
private MenuItem parent;
public MenuItem getParent() {
return parent;
}
If I want to move a child element to a different node, different kind of problems appear:
1. If I only adds the element to the new list: the original list will have a gap in the ordering, and will be a null element there
Code:
list.add(list.indexOf(target),insertee);
2.If I delete the element from the old list and then try to add: I get the following exception "org.hibernate.ObjectDeletedException: deleted entity passed to persist"
Code:
list.add(list.indexOf(target),insertee);
origList.remove(insertee);
or this behaves the same:
Code:
origList.remove(insertee);
list.add(list.indexOf(target),insertee);
any tips?
Thanks:
Bence